自动生成新的单据并进行保存提交审核插件原创
金蝶云社区-小抩
小抩
8人赞赏了该文章 144次浏览 未经作者许可,禁止转载编辑于2023年12月27日 16:19:39

 string ret = "";

                        Kingdee.BOS.Contracts.IMetaDataService metadataService = ServiceHelper.GetService<Kingdee.BOS.Contracts.IMetaDataService>();

                        FormMetadata Sal_BatchAdjustPrice_meta = metadataService.Load(this.Context, "WRKJ_KHZHYEGLB") as FormMetadata;

                        BusinessInfo Sal_BatchAdjustPrice_info = Sal_BatchAdjustPrice_meta.BusinessInfo;

                        DynamicObject Sal_BatchAdjustPrice_Bill = new DynamicObject(Sal_BatchAdjustPrice_info.GetDynamicObjectType());

                        DynamicObjectCollection entirys = Sal_BatchAdjustPrice_Bill["FEntity"] as DynamicObjectCollection;

                        DynamicObject entity = entirys.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;

                        if (FCONTACTUNIT > 0)

                        {

                            BaseDataField materialidobj = Sal_BatchAdjustPrice_info.GetField("Fclient") as BaseDataField;

                            var materialData = BusinessDataServiceHelper.LoadSingle(this.Context, FCONTACTUNIT, materialidobj.RefFormDynamicObjectType);

                            if (materialData != null)

                            {

                                entity["Fclient_Id"] = FCONTACTUNIT;

                                entity["Fclient"] = materialData;

                            }

                        }

                        entity["FDateUpdata"] = Convert.ToDateTime(DateTime.Now).ToString("yyyy-MM-dd");

                        entirys.Add(entity);

                        Field CreateDate = Sal_BatchAdjustPrice_info.GetField("FDate");

                        CreateDate.DynamicProperty.SetValue(Sal_BatchAdjustPrice_Bill, Convert.ToDateTime(DateTime.Now).ToString("yyyy-MM-dd"));

                        OperateOption option = OperateOption.Create();

                        option.SetIgnoreWarning(true);// 保存

                        IOperationResult result = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Save(this.Context, Sal_BatchAdjustPrice_info, new DynamicObject[] { Sal_BatchAdjustPrice_Bill }, option, "Save");

                        if (result.IsSuccess)

                        {

                            ret = billtypename + ":" + Sal_BatchAdjustPrice_Bill["BillNo"].ToString() + "\r\n";

                            object[] primaryKeys = result.SuccessDataEnity.Select(u => u.GetPrimaryKeyValue()).ToArray();

                            // 提交

                            IOperationResult submitResult = BusinessDataServiceHelper.Submit(this.Context, Sal_BatchAdjustPrice_info, primaryKeys, "Submit", option);

                            if (submitResult.IsSuccess)

                            {

                                // 审核

                                IOperationResult auditResult = BusinessDataServiceHelper.Audit(this.Context, Sal_BatchAdjustPrice_info, primaryKeys, option);

                                if (!auditResult.IsSuccess)

                                {

                                    ret = billtypename + ":" + auditResult.ValidationErrors[0].Message + "\r\n";

                                }

                            }

                            else

                            {

                                ret = billtypename + ":" + submitResult.ValidationErrors[0].Message + "\r\n";

                            }

                        }

                        else

                        {

                            ret = billtypename + ":" + result.ValidationErrors[0].Message + "\r\n";


                        }


赞 8