
## 问题背景
目前标准产品只能从打开的表单里通过实体服务规则配置【设置弹性域缺省值】实现物料辅助属性默认值的携带。但计划订单投放采购申请单完成前过程中没有建立视图进行保存,不会触发这类依赖视图值更新或表单操作执行的规则。因此需要在计划订单投放采购申请单时补充一段获取辅助属性的缺省值处理,以完善解决投放的采购申请单取价依赖辅助属性的逻辑问题。
## 样例插件
插件为单据转换插件,需要注册在【计划订单】转换【采购申请单】的转换规则。对这块未有了解请先阅读以下文章:
·[单据转换规则说明](https://vip.kingdee.com/questions/7439/answers/10933)
·[单据转换插件知识帖合集](https://vip.kingdee.com/article/279657956822376704)
```csharp
using Kingdee.BOS.App.Core;
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.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Kingdee.K3.BD.ServiceHelper;
using Kingdee.K3.Core.MFG;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.K3.MFG.App;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SampleAppPlugIn
{
public class SetDefaultFexValue : AbstractConvertPlugIn
{
public override void OnAfterCreateLink(CreateLinkEventArgs e)
{
var entrys = e.TargetExtendedDataEntities.FindByEntityKey("FEntity");
FormMetadata auxMeta = MetaDataServiceHelper.Load(this.Context, MFGFormIdConst.SubSys_BD.BD_FLEXSITEMDETAILV) as FormMetadata;
List<DynamicObject> auxPropObjects = new List<DynamicObject>();
foreach (var entry in entrys)
{
long auxPropId = entry.DataEntity.GetDynamicValue<long>("AuxpropId_Id");
if (auxPropId > 0) continue;
DynamicObject mtrl = entry.DataEntity.GetDynamicValue<DynamicObject>("MaterialId");
if (mtrl == null) continue;
DynamicObjectCollection mtrlAuxProps = mtrl["MaterialAuxPty"] as DynamicObjectCollection;
if (mtrlAuxProps.IsEmpty() || mtrlAuxProps.Any(x => x.GetDynamicValue<bool>("IsEnable1") == true) == false)
{
continue;
}
string mtrlId = entry.DataEntity.GetDynamicValue<string>("MaterialId_Id");
var defPropertyValues = BDFlexServiceHelper.GetAuxPtyValueDefInfo(this.Context, mtrlId, "");
if (defPropertyValues.IsEmpty()) continue;
DynamicObject auxPropObject = entry.DataEntity.GetDynamicValue<DynamicObject>("AuxpropId");
if (auxPropObject == null)
{
auxPropObject = new DynamicObject(auxMeta.BusinessInfo.GetDynamicObjectType());
auxPropObjects.Add(auxPropObject);
foreach (var defPV in defPropertyValues)
{
string fflexNumber = defPV.GetDynamicValue<string>("FFlexNumber");
Field f = auxMeta.BusinessInfo.GetField(fflexNumber);
auxPropObject.SetDynamicObjectItemValue(f.PropertyName + "_Id", defPV["FDefValueId"]);
}
entry.DataEntity.SetDynamicObjectItemValue("AuxpropId", auxPropObject);
}
}
if (!auxPropObjects.IsEmpty())
{
DBServiceHelper.LoadReferenceObject(this.Context, auxPropObjects.ToArray(), auxMeta.BusinessInfo.GetDynamicObjectType(), false);
FlexSaveService sv = new FlexSaveService(this.Context, "Save");
MFGFlexHelperUtil.SaveFlexFixedColumn(this.Context, e.TargetBusinessInfo, e.TargetExte