jieujieu 发表于 2022-9-16 00:24:40

U8触发器有什么注意事项?

在库存单据上做了触发器,从项目档案更新一个表头自定义项值,验证效果正常。

但是存货核算,正常单据记账报错,把触发器禁用了,正常单据记账就正常了。
请问需要怎么做触发器,才能不影响系统的功能,U8的触发器有哪些需要注意的事项。
附件是2个单据的触发器脚本,都是实现类似的功能。

jieujieu 发表于 2022-9-16 00:27:41

CREATE TRIGGERxsckd_update_fitemss05
   ON rdrecord32 --销售出库单主表
   FOR INSERT,UPDATE
AS
BEGIN
        if (select cDefine11 from rdrecord32 wherecCode=(select cCode from inserted) ) is null--如果销售流水号为空
       
          begin
                update rdrecord32 set cDefine13=NULL,cDefine3=NULLwherecDefine11 IS NULL   --清空其他2个字段
          end
       
        else            --如果销售流水号不为空
       
          begin          
                update rdrecord32 set cDefine13=fitemss05.销售项目编码,cDefine3=fitemss05.客户名称 from fitemss05    --从项目目录“新销售流水号”中更新其它2个字段
                wherecDefine11=fitemss05.citemcode and cCode=(select cCode from inserted)
           end
END

jieujieu 发表于 2022-9-16 00:27:17

附件下载好像要积分,我把代码贴出来:

CREATE TRIGGERqtckd_update_fitemss05
   ON RdRecord09 --其他出库单主表
   FOR INSERT,UPDATE
AS
BEGIN
        if (select cDefine11 from RdRecord09 wherecCode=(select cCode from inserted) ) is null--如果销售流水号为空
       
          begin
                update RdRecord09 set cDefine13=NULL,cDefine3=NULLwherecDefine11 IS NULL   --清空其他2个字段
          end
       
        else            --如果销售流水号不为空
       
          begin          
                update RdRecord09 set cDefine13=fitemss05.销售项目编码,cDefine3=fitemss05.客户名称 from fitemss05    --从项目目录“新销售流水号”中更新其它2个字段
                wherecDefine11=fitemss05.citemcode and cCode=(select cCode from inserted)
           end
END

consofor 发表于 2022-9-17 13:53:10

本帖最后由 consofor 于 2022-9-17 13:56 编辑

CREATE TRIGGERqtckd_update_fitemss05
   ON RdRecord09 --其他出库单主表
   FOR INSERT,UPDATE   ------ 不清楚更新触发有啥意义
AS
BEGIN
set nocount on ;----设置无返回信息
   if update(cHandler )   ----更新条件
      if (select cDefine11 from RdRecord09 wherecCode=(select cCode from inserted) ) is null--如果销售流水号为空
      
          begin
                update RdRecord09 set cDefine13=NULL,cDefine3=NULLwherecDefine11 IS NULL   --清空其他2个字段
          end
      
      else            --如果销售流水号不为空
      
          begin         
                update RdRecord09 set cDefine13=fitemss05.销售项目编码,cDefine3=fitemss05.客户名称 from fitemss05    --从项目目录“新销售流水号”中更新其它2个字段
                wherecDefine11=fitemss05.citemcode and cCode=(select cCode from inserted)
         end
END

kandk99999 发表于 2022-9-19 18:52:08

学习学习

junjietangs 发表于 2022-9-20 16:28:33

附件是2个单据的触发器脚本,都是实现类似的功能。

jieujieu 发表于 2022-9-21 16:51:24

consofor 发表于 2022-9-17 13:53
CREATE TRIGGERqtckd_update_fitemss05
   ON RdRecord09 --其他出库单主表
   FOR INSERT,UPDATE   ---- ...

感谢您的答复!有一个条语句没看懂: if update(cHandler ),这个cHandler指什么?
再次请教。

jieujieu 发表于 2022-9-21 17:10:28

consofor 发表于 2022-9-17 13:53
CREATE TRIGGERqtckd_update_fitemss05
   ON RdRecord09 --其他出库单主表
   FOR INSERT,UPDATE   ---- ...

搞清楚了,是一个字段名;P

chyp1123 发表于 2022-9-23 10:33:51

学习一下学习一下学习一下

chyp1123 发表于 2022-9-23 10:36:21

学习一下学习一下学习一下

chyp1123 发表于 2022-9-23 13:59:13

学习一下学习一下学习一下

刘佳佳 发表于 2022-10-8 13:59:18

学习一下

AltLau 发表于 2022-10-12 13:16:38

看来做个用友的系统管理员还真不简单:victory:
页: [1]
查看完整版本: U8触发器有什么注意事项?