保存校验多选基础资料唯一性

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

保存校验多选基础资料唯一性

@[TOC](目录) ### 背景 在单据上二开自定义多选基础资料之后,在保存操作的校验规则中的唯一性校验找不到该字段。BOS配置不支持对多选基础资料进行唯一性校验,因为多选基础资料数据实际上存在另一个独立的数据表中。那有些场景确有此需求应该如何实现呢?考虑**二开保存校验器插件**实现。 ### 步骤 1. 新增多选基础资料字段 2. 到操作列表找到保存操作 3. 注册python脚本 ![image.webp](/download/0100f8b5b80126ea4c84b9ed1e5898eb6985.webp) ### Python脚本(以供应商联系人页签为例) ```python import clr clr.AddReference("mscorlib") clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.App") clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.Contracts') clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference('Newtonsoft.Json') from Kingdee.BOS import * from Kingdee.BOS.App.Data import * from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * from Kingdee.BOS.Util import * from System import * from System.Collections.Generic import * from System.Data import * from Kingdee.BOS.Core import * from Kingdee.BOS.Orm.DataEntity import * from Kingdee.BOS.DataEntity import * from Kingdee.BOS.Core.DynamicForm import * from System.Collections.Generic import List from Newtonsoft.Json import JsonConvert from Newtonsoft.Json.Linq import * from Kingdee.BOS.Core.Validation import * from Kingdee.BOS.Log import Logger def OnAddValidators(e): validator = OneValidator() validator.EntityKey = "FBillHead" validator.AlwaysValidate = True e.Validators.Add(validator) class OneValidator(AbstractValidator): def Validate(self, dataEntities, validateContext,ctx): for bill in dataEntities: contact = bill["SupplierContact"] baseIds = List[long]() seq=0 for contactEntry in contact: baseMul = contactEntry["FMulBase_apv"] seq+=1 for mul in baseMul: baseId = mul["FMulBase_apv_Id"] if not baseIds.Contains(baseId): baseIds.Add(baseId) else: baseId = mul["FMulBase_apv"] baseName = str(baseId["Name"]) billId = str(bill["Id"]) msg = '''供应商【{0}】联系人第{1}行多选基础资料存在内容【{2}】重复,请检查'''.format(bill.BillNo, seq,baseName) info = ValidationErrorInfo("",billId, bill.DataEntityIndex,seq,billId, msg,"多选基础资料校验",ErrorLevel.Error) validateContext.AddError(None,info) ``` ==自定义字段名称为FMulBase_apv,注意替换。== ### 效果 1. 数据内容 ![image.webp](/download/0100d2399175296043438783330483dc79fd.webp) 2. 校验提示信息 ![image.webp](/download/01006ad98892db1c4de086f02ae5af02dc17.webp) **其他更多文章入口:**[https://vip.kingdee.com/link/s/lbRPP](https://vip.kingdee.com/link/s/lbRPP)

保存校验多选基础资料唯一性

@[TOC](目录)### 背景在单据上二开自定义多选基础资料之后,在保存操作的校验规则中的唯一性校验找不到该字段。BOS配置不支持对多选基础资...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息