已有入库单对象以及物料的编码,在代码中设置分录的物料为已知编码为的物料。
DynamicObjectCollection entryItems = e.DataEntitys[0]["InStockEntry"] as DynamicObjectCollection;
foreach (var item in entryItems)
{
var m = item["MaterialId"] as DynamicObject;
if (m != null)
{
FormMetadata matMetaData = (FormMetadata)metadataSvr.Load(this.Context,"BD_MATERIAL") as FormMetadata; //获取物料元数据
var mtls = DBServiceHelper.ExecuteDynamicObject(ctx, "select top 1 FMATERIALID, FNUMBER from T_BD_MATERIAL t where t.FNUMBER='" + m["Number"].ToString() + "'");
long lPKValue = 0;
Int64.TryParse(mtls[0]["FMATERIALID"].ToString(), out lPKValue);
var mobj = BusinessDataServiceHelper.LoadSingle(ctx, lPKValue, matMetaData.BusinessInfo.GetDynamicObjectType());
item["MaterialId"] = mobj;
}
}
物料获取是对的,但是最后一句 item["MaterialId"] = mobj;出现了错误信息:Int64 is not iterable
推荐阅读