【二开插件】使用WebApi进行代码下推并自动保存审核单据原创
5人赞赏了该文章
1,715次浏览
编辑于2023年01月27日 12:57:26
WebApi下推
优点:只需要知道上游单据编号或者内码就可以,构造的下推参数比较简单,设置保存审核也简单
缺点:会自动保存
代码:
if (webApiAutoPushInvoice(ctx, msg, out string message)) { LogObject log = new LogObject { pkValue = "0", Description = "下推发票成功,发票号:"+message , OperateName = "下推发票_成功", ObjectTypeId = "BOS_SCHEDULETYPE", SubSystemId = "BOS", Environment = OperatingEnvironment.BizOperate }; logs.Add(log); } else { LogObject log = new LogObject { pkValue = "0", Description = "自动下推发票失败,失败原因:" + message , OperateName = "下推发票_失败", ObjectTypeId = "BOS_SCHEDULETYPE", SubSystemId = "BOS", Environment = OperatingEnvironment.BizOperate }; logs.Add(log); }
下推保存代码
private bool webApiAutoPushInvoice(Context ctx, string msg, out string message) { bool result = false; message = string.Empty; JObject data = new JObject { { "Numbers", msg }, { "RuleId", "IV_ReceivableToSalesOC_Entry" }, { "IsDraftWhenSaveFail", "false" } }; //下推 Dictionary<string, object> pushResult = WebApiServiceCall.Push(ctx, "AR_receivable", data.ToString()) as Dictionary<string, object>; Dictionary<string, object> response = (pushResult["Result"] as Dictionary<string, object>)["ResponseStatus"] as Dictionary<string, object>; if (Convert.ToBoolean(response["IsSuccess"])) { //自动保存提交审核 Dictionary<string, object> successEntity = (response["SuccessEntitys"] as List<object>).First() as Dictionary<string, object>; string FID = successEntity["Id"].ToString(); Dictionary<string, object> saveResult = WebApiServiceCall.Save(ctx, "IV_SALESOC", GetSaveParamStr(FID)) as Dictionary<string, object>; Dictionary<string, object> saveResponse = (saveResult["Result"] as Dictionary<string, object>)["ResponseStatus"] as Dictionary<string, object>; if (!Convert.ToBoolean(saveResponse["IsSuccess"])) { Dictionary<string, object> Errors = (saveResponse["Errors"] as List<object>).First() as Dictionary<string, object>; message = Errors["Message"].ToString(); } else { result = true; message =successEntity["Number"].ToString(); } } else { Dictionary<string, object> Errors = (response["Errors"] as List<object>).First() as Dictionary<string, object>; message = Errors["Message"].ToString(); } return result; }
自动保存审核参数构造
private string GetSaveParamStr(string FID) { JObject param = new JObject(); param.Add("Creator", ""); JArray needUpdateFields = new JArray(); param.Add("NeedUpDateFields", needUpdateFields); param.Add("NeedReturnFields", new JArray()); param.Add("IsDeleteEntry", true); param.Add("SubSystemId", ""); param.Add("IsVerifyBaseDataField", false); param.Add("IsEntryBatchFill", true); param.Add("ValidateFlag", true); param.Add("NumberSearch", true); param.Add("InterationFlags", ""); param.Add("IsAutoSubmitAndAudit", true); //设置true就是自动提交审核 JObject order = new JObject(); param.Add("Model", order); order.Add("FID", FID); return param.ToString(); }
如果是明细行下推
JObject data = new JObject { { "EntryIds", string.Join(",", ids) }, //分录内码 { "RuleId", "DeliveryNotice-OutStock" }, { "IsDraftWhenSaveFail", "false" } };
赞 5
5人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读