单据保存报错
金蝶云社区-云社区用户6SBo0821
云社区用户6SBo0821
0人赞赏了该文章 1,236次浏览 未经作者许可,禁止转载编辑于2015年11月09日 21:10:14

服务端单据保存时报错:

代码:
public IOperationResult Save(BOS.Context ctx, BeginOperationTransactionArgs e)
{
//获取元数据
FormMetadata meta = BOS.ServiceHelper.MetaDataServiceHelper.Load(this.Context, "STK_MISCELLANEOUS", null) as FormMetadata;
BusinessInfo bi = meta.BusinessInfo;
IViewService ivs = ServiceHelper.GetService();
DynamicObject obj = new DynamicObject(bi.GetDynamicObjectType());

//基础资料
IMetaDataService mds = ServiceHelper.GetService();
FormMetadata fmStock = mds.Load(this.Context, "BD_STOCK") as FormMetadata;
FormMetadata fmSupplier = mds.Load(this.Context, "BD_SUPPLIER") as FormMetadata;
string ownertype = "BD_OwnerOrg";
FormMetadata fmOwner = mds.Load(this.Context, ownertype) as FormMetadata;
FormMetadata fmCurrency = mds.Load(this.Context, "BD_CURRENCY") as FormMetadata;
FormMetadata fmCust = mds.Load(this.Context, "BD_CUSTOMER") as FormMetadata;
FormMetadata fmDepId = mds.Load(this.Context, "BD_DEPARTMENT") as FormMetadata;
FormMetadata fmMaterial = mds.Load(this.Context, "BD_MATERIAL") as FormMetadata;
FormMetadata fmUnit = mds.Load(this.Context, "BD_Unit") as FormMetadata;
FormMetadata fmStockStatus = mds.Load(ctx, "BD_STOCKSTATUS") as FormMetadata;
FormMetadata fmBillType = mds.Load(ctx, "BOS_BILLTYPE") as FormMetadata;

OperateOption op = OperateOption.Create();

#region 根据元数据设置对应的数据
obj["ID"] = 0;
obj["DocumentStatus"] = "A";
obj["CANCELSTATUS"] = "A";
obj["BillTypeID_ID"] = "d772ead981e748d69dda1caac7583f8c";
obj["BillTypeID"] = ivs.LoadSingle(this.Context, "d772ead981e748d69dda1caac7583f8c", fmBillType.BusinessInfo.GetDynamicObjectType());
obj["FStockOrgId_Id"] = "100022";
obj["FStockOrgId"] = ivs.LoadSingle(this.Context, "100022", fmStock.BusinessInfo.GetDynamicObjectType());
obj["StockDirect"] = 0;
obj["FDate"] = DateTime.Now.Date;
obj["OwnerTypeIdHead"] = ownertype;
obj["OwnerIdHead_Id"] = "100006";
obj["OwnerIdHead"] = ivs.LoadSingle(this.Context, "100006", fmOwner.BusinessInfo.GetDynamicObjectType());
obj["BaseCurrId_Id"] = "1";
obj["BaseCurrId"] = ivs.LoadSingle(this.Context, "1", fmCurrency.BusinessInfo.GetDynamicObjectType());
obj["SUPPLIERID_Id"] = "100036";
obj["SUPPLIERID"] = ivs.LoadSingle(this.Context, "100036", fmSupplier.BusinessInfo.GetDynamicObjectType());
obj["DEPTID_Id"] = "100202";
obj["DEPTID"] = ivs.LoadSingle(this.Context, "100202", fmDepId.BusinessInfo.GetDynamicObjectType());

DynamicObjectCollection entity = obj["STK_MISCELLANEOUSENTRY"] as DynamicObjectCollection;
entity.Clear();
for (int i = 0; i < 3; i++)
{
DynamicObject entry = new DynamicObject(entity.DynamicCollectionItemPropertyType);
entry["MaterialId_Id"] = "100596";
entry["MaterialId"] = ivs.LoadSingle(this.Context, "100596", fmMaterial.BusinessInfo.GetDynamicObjectType());
entry["FUnitID_Id"] = "10087";
entry["FUnitID"] = ivs.LoadSingle(this.Context, "10087", fmUnit.BusinessInfo.GetDynamicObjectType());
entry["FSTOCKID_Id"] = "121883";
entry["FSTOCKID"] = ivs.LoadSingle(this.Context, "121883", fmStock.BusinessInfo.GetDynamicObjectType());
entry["STOCKSTATUSID_Id"] = "10000";
entry["STOCKSTATUSID"] = ivs.LoadSingle(this.Context, "10000", fmStockStatus.BusinessInfo.GetDynamicObjectType());
entry["FQty"] = 10 * i + 1;
entry["FPrice"] = i + 10;
entry["FAmount"] = (i + 1) * 100;

entity.Add(entry);
}

#endregion

//保存服务
ISaveService saveService = ServiceHelper.GetService();
DynamicObject[] objResults = new DynamicObject[] { obj };
IOperationResult result = saveService.Save(this.Context, bi, objResults, OperateOption.Create());

if ((result.ValidationErrors != null && result.ValidationErrors.Count > 0)
|| (result.OperateResult != null && result.OperateResult.Count > 0))
{
result.IsSuccess = false;
}

return result;
}