金蝶云星空单据转换插件如何获取webapi调用的单据下推携带的自定义字段进行处理
#region 初始化 public override void OnInitVariable(InitVariableEventArgs e) { base.OnInitVariable(e); bool isReason = this.Option.TryGetVariableValue<string>("FPaReason", out reason); bool isName = this.Option.TryGetVariableValue<string>("FName", out name); } #endregion
1、转换插件,无则新增,继承插件抽象类。添加引用。
2、初始化事件获取接口传递的值
#region 初始化
public override void OnInitVariable(InitVariableEventArgs e)
{
base.OnInitVariable(e);
bool isReason = this.Option.TryGetVariableValue<string>("FPaReason", out reason);
bool isName = this.Option.TryGetVariableValue<string>("FName", out name);
}
#endregion
3、单据转换后事件
#region <转换后 AfterConvert> public override void AfterConvert(AfterConvertEventArgs e) { base.AfterConvert(e); var billHead = e.Result.FindByEntityKey("FBillHead"); //目标单 foreach (var item in billHead) { //FName if (name.IsNullOrEmptyOrWhiteSpace()) { object date = item["CreateDate"]; name = date.ToString(); } item.DataEntity["Name"] = name; if (reason.IsNullOrEmptyOrWhiteSpace()) { reason = "7590e08cf9064cdfbfe7e3a7fb0741e2"; } else { //调价原因 转 基础资料 var entry = BOSCommon.GetMetaDynamic(this.Context, "BOS_ASSISTANTDATA_DETAIL", string.Format(@"FDATAVALUE = '{0}'", reason), "FENTRYID"); if (entry == null) { //先不考虑无 ,默认:定期询价 reason = "7590e08cf9064cdfbfe7e3a7fb0741e2"; } else { reason= Convert.ToString(entry["FENTRYID"]); } } //单选辅助资料:调价原因 BaseDataField reasonField = e.TargetBusinessInfo.GetField("FPaReason") as BaseDataField; BOSCommon.SetBaseDataFieldValue(this.Context, reasonField, item.DataEntity,reason ); } } #endregion <转换后 AfterConvert>
文本转基础资料需参考:
4、编译,新插件要先注册。
5、webapi调用。
请求json格式:
{ "Ids": "", "Numbers": [], "EntryIds": "100005,100003,100001,100002", "RuleId": "", "TargetBillTypeId": "", "TargetOrgId": 0, "TargetFormId": "PUR_PAT", "IsEnableDefaultRule": "true", "IsDraftWhenSaveFail": "false", "CustomParams": {"FPaReason":"定期询价","FName":"测试下推3"} }
返回详细结果:
{"Result":{"ResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[{"Id":100011,"Number":"CGTJ0006","DIndex":0,"EntryIds":{"FPUR_PATENTRY":[100019,100020,100021]}}],"SuccessMessages":[],"MsgCode":0},"ConvertResponseStatus":{"IsSuccess":true,"Errors":[],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":0}}}