保存校验多选基础资料唯一性
@[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配置不支持对多选基础资...
点击下载文档
上一篇:采购订单变更状态控制数据自动处理下一篇:获取采购价目表价格服务失败排查
本文2024-09-23 02:34:09发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-153289.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章