单据转换多个单据体转换赋值的插件实现案例原创
13人赞赏了该文章
3,605次浏览
编辑于2022年11月04日 17:15:49
一、【业务需求】
一个单据有多个个单据体,想在单据转换中配置下推功能,可是不支持多单据体字段转换映射的配置
二、【分析实现】
单据转换中源单中被选择的字段只能来源于一个单据体,目标单中做映射的字段也只能来源于一个单据体,当单据转换字段配置涉及多个单据体字段时,平台目前无法支持。只能通过二开转换插件处理,对单据体数据携带赋值。
解决方案:
二开一个单据转换插件(基类=Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.AbstractConvertPlugIn,Kingdee.BOS.Core.dll)。重载其中的AfterConvert事件,根据所选的源单,自行读取上游单据对应的单据体数据,然后填写到目标单对应单据体中。
以出库申请单-其他出库单为例,分别在申请单和出库单扩展一个单据体,添加相应的字段,简单化处理,配置物料、批号、备注字段。
using Kingdee.BOS; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.App.Core; using System.Collections.Generic; using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args; using System; using Kingdee.BOS.Util; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Orm.Metadata.DataEntity; namespace Demo { public class CusEntityMapSetEx : AbstractConvertPlugIn { private List<long> fids = new List<long>(); public override void OnGetSourceData(GetSourceDataEventArgs e) { base.OnGetSourceData(e); if (e.SourceBusinessInfo.GetForm().Id.EqualsIgnoreCase("STK_OutStockApply")) { foreach (DynamicObject data in e.SourceData) { long fid = Convert.ToInt64(data["FID"]); if (!fids.Contains(fid)) { fids.Add(fid); } } } } public override void AfterConvert(BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e) { List<DynamicObject> sourceBillDatas = new List<DynamicObject>(); IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); BaseDataField materialExtfield = e.TargetBusinessInfo.GetField("FMaterialId_Ext") as BaseDataField; var dataObjs = e.Result.FindByEntityKey("FBillHead"); foreach (var obj in dataObjs) { foreach (var fid in fids) { FormMetadata metadata = MetaDataServiceHelper.Load(this.Context, "STK_OutStockApply") as FormMetadata; DynamicObject[] soDatas = BusinessDataServiceHelper.Load(this.Context, new object[] { fid }, metadata.BusinessInfo.GetDynamicObjectType()); if (soDatas.Length > 0) { sourceBillDatas.AddRange(soDatas); } } DynamicObjectType entryDyType = e.TargetBusinessInfo.GetEntity("FEntity1").DynamicObjectType; DynamicObjectCollection cusEntrys = obj["CustEntry"] as DynamicObjectCollection; if (cusEntrys == null) { cusEntrys = new DynamicObjectCollection(entryDyType, obj); } foreach (DynamicObject item in sourceBillDatas) { DynamicObjectCollection cusEntry = item["CustEntry"] as DynamicObjectCollection; DynamicObject material = viewService.LoadSingle(this.Context, entry["MaterialId_Ext_Id"], materialExtfield.RefFormDynamicObjectType); DynamicObject dy = new DynamicObject(entryDyType); dy["MaterialId_Ext_Id"] = entry["MaterialId_Ext_Id"]; dy["MaterialId_Ext"] = material; dy["Lot_Ext_Text"] = entry["Lot_Ext_Text"]; dy["Note_Ext"] = "原单编号: " + Convert.ToString(item["BillNo"]); cusEntrys.Add(dy); } } } }
实现效果:
1、出库申请单,扩展单据体数据
2、下推其他出库单,对应单据体赋值
相关参考:
多单据体下推转换示例.rar(1.23KB)
赞 13
13人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!