社区中平台的老师提供有二开案例,通过表单插件,用代码去主动触发实体服务规则,参考:
研究了下尝试转换为Python实现,这里记录一下
import clr clr.AddReference('System') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.Core') from System import * from System.Reflection import * from System import StringComparison from Kingdee.BOS.Core import * from Kingdee.BOS.Core.Metadata.EntityElement import * from Kingdee.BOS.Core.DependencyRules import * from System.Collections.Generic import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * from Kingdee.BOS.Core.DynamicForm import * def BarItemClick(e): if e.BarItemKey.Equals("tbButton_1", StringComparison.OrdinalIgnoreCase): ctx = BOSActionExecuteContext(this.View) datas = List[object]() datas.Add(this.Model.DataObject) SetDataEntities(ctx, datas) entityRule = None for r1 in this.View.RuleContainer.Rules: # type: EntityRule if r1.ToString().rfind("1 == 1") > 0: entityRule = r1 break if entityRule is not None: entityRule.Execute(ctx) if e.BarItemKey.Equals("tbButton_2", StringComparison.OrdinalIgnoreCase): this.View.RuleContainer.RaiseDataChanged("FNote", this.Model.DataObject, BOSActionExecuteContext(this.View)) def SetDataEntities(ctx, value): fieleName = "_dataEntities" # clr.GetClrType() 对应C#的typeof fieldInfo = clr.GetClrType(BOSActionExecuteContext).GetField(fieleName, BindingFlags.Instance | BindingFlags.NonPublic) if fieldInfo is not None: fieldInfo.SetValue(ctx, value)
# dir(this.View.RuleContainer.Rules)
#['Add', 'Clear', 'ClearItems', 'Contains', 'CopyTo', 'Count', 'Equals', 'GetEnumerator', 'GetHashCode', 'GetType', 'IndexOf', 'Insert', 'InsertItem', 'IsReadOnly', 'IsSynchronized', 'Item', 'Items', 'MemberwiseClone', 'ReferenceEquals', 'Remove', 'RemoveAt', 'RemoveItem', 'SetItem', 'SyncRoot', 'ToString', '__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__']
插件触发实体服务规则值更新-python.rar(0.94KB)