单据转换插件里,通过AfterConvert事件来修改目标单数据包里的基础数据字段原创
25人赞赏了该文章
1,189次浏览
编辑于2023年04月11日 16:09:15
记录一个下推时,能成功修改目标单里的基础数据字段的方法
using Kingdee.BOS.App.Core.Utils; using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Core.Metadata.Util; using Kingdee.BOS.Core.Util; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; namespace WPBR.FormicPhase2.SCM.ServicePlugIn.ConvertServicePlugIn { [Description("PO下推AP转换插件")] [HotUpdate] public class PoToApConvertServicePlugIn : AbstractConvertPlugIn { public override void AfterConvert(AfterConvertEventArgs e) { base.AfterConvert(e); if (e.Result == null) { return; } DynamicObject dynamicObject = e.Result.FindByEntityKey("FBillHead")[0].DataEntity; var profitCenter = dynamicObject["FProfitCenter_id"]; var department = dynamicObject["FDepartment_id"]; if (department == null || profitCenter == null) { return; } var organize = dynamicObject["SETTLEORGID_Id"]; var result = DBUtils.ExecuteDynamicObject(e.Context, $"SELECT * FROM MappingConfig_Entity where FOrganization = {organize} and FDepartment = {department} and FProfitCenter ={profitCenter}"); var mappingData = result.IsEmpty() == false ? result.First() : null; if (mappingData != null) { var accountPrimaryKey = mappingData["FAccount"]; var dataField = e.TargetBusinessInfo.GetField("FAccount") as BaseDataField; DynamicObject[] results = BusinessDataServiceHelper.Load(this.Context, new[] { accountPrimaryKey }, dataField.RefFormDynamicObjectType); //set value dynamicObject["FAccount"] = results.FirstOrDefault(); } } } }
关键代码就是最后几行,必须把基础资料的DynamicObject获取到,然后直接赋值给目标单的DynamicObject对应的字段。
赞 25
25人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读