【自动下推二开插件】设置分录下推数据和目标单据类型

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

【自动下推二开插件】设置分录下推数据和目标单据类型

【官方知识】:

 1.使用代码实现单据下推

 2.在插件中实现自定义下推(完整代码)


设置要下推的分录数据

ListSelectedRowCollection selectedRows = new  ListSelectedRowCollection();
foreach (string id in listIds)
{
       //单据id,单据体分录id
       ListSelectedRow row = new ListSelectedRow(billId, id, 0,  "DM_PlanReport");//设置分录id,单据id可不写
       row.EntryEntityKey = "FDMReportGoods"; //单据体标识
       selectedRows.Add(row);
}


子单据体下推构建参数


调用下推

  • 下推时,如果单据转换规则设置了目标单据类型映射,就必须要设置TargetBillTypeId。

  • 如果不设置目标单的单据类型会使用默认类型

 private DynamicObject[] autoPush(Context ctx, ListSelectedRow[] selectedRows, ConvertRuleElement rule, string targetFormId, Dictionary<string, object> custParams)
        {
            // 调用下推服务,生成下游单据数据包
            ConvertOperationResult operationResult = null;
            try
            {
                PushArgs pushArgs = new PushArgs(rule, selectedRows)
                {
                    TargetBillTypeId = "",                 // 请设定目标单据单据类型。如无单据类型,可以空字符
                    TargetOrgId = 0,                       // 请设定目标单据主业务组织。如无主业务组织,可以为0
                    CustomParams = custParams  // 可以传递额外附加的参数给单据转换插件,如无此需求,可以忽略
                };
                //如果规则设置了目标单据类型,必须设置TargetBillTypeId
                Collection<ConvertPolicyElement> policies = rule.Policies;
                //单据类型映射
                ConvertPolicyElement policy = policies.Where(p => p is BillTypeMapPolicyElement).FirstOrDefault();
                if (policy != null)
                {
                    BillTypeMapPolicyElement billTypeMapPolicy = policy as BillTypeMapPolicyElement;
                    if (billTypeMapPolicy != null)
                    {
                        Collection<BillTypeMapElement> billTypeMaps = billTypeMapPolicy.BillTypeMaps;
                        if (billTypeMaps != null)
                        {
                            foreach (BillTypeMapElement billTypeMap in billTypeMaps)
                            {
                                if (billTypeMap.SourceBillTypeId == sourceBillTypeId) //单据类型如果为全部,可以写(All)
                                {
                                    pushArgs.TargetBillTypeId= billTypeMap.TargetBillTypeId;
                                    break;
                                }
                            }
                        }
                    }
                }
                //执行下推操作,并获取下推结果
                operationResult = ServiceFactory.GetService<IConvertService>(ctx).Push(ctx, pushArgs, OperateOption.Create());
            }
            catch (KDExceptionValidate ex)
            {
                throw new Exception(ex.ToString());
            }
            catch (KDException ex)
            {
                throw new Exception(ex.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            // 获取生成的目标单据数据包
            DynamicObject[] objs = (from p in operationResult.TargetDataEntities
                                    select p.DataEntity).ToArray();
            return objs;
        }


展示数据

public void showBill(string formId, DynamicObject bill)
        {
            BillShowParameter param = new BillShowParameter();
            param.ParentPageId = this.View.PageId;
            param.FormId = formId;
            //param.PKey = billId;
            param.Status = OperationStatus.ADDNEW;
            param.CreateFrom = CreateFrom.Push;
            param.AllowNavigation = false;
            string sessionKey = FormConst.ConvParamKey_OneResultSessionKey;// "_ConvertSessionKey";
            string sessionName = FormConst.ConvParamKey_OneResultSessionName;// "ConverOneResult";
            param.CustomParams.Add(sessionKey, sessionName);
            param.OpenStyle.ShowType = ShowType.MainNewTabPage;
            this.View.Session[sessionName] = bill;
            this.View.ShowForm(param);
}


单据类型映射数据包截图:

图片.webp


   if (billTypeMap.SourceBillTypeId == sourceBillTypeId) //单据类型如果为全部,可以写(All)                                 {                                     pushArgs.TargetBillTypeId= billTypeMap.TargetBillTypeId;                                     break;                                 }

老师这个参数怎么取sourceBillTypeId??


很好,简洁明了,通俗易懂,作者看来对方面很有研究,学到了,感谢。

解决了燃眉之急!很棒!学会了!点个赞!


学习了

【自动下推二开插件】设置分录下推数据和目标单据类型

【官方知识】: 1.使用代码实现单据下推 2.在插件中实现自定义下推(完整代码)设置要下推的分录数据ListSelectedRowCollection selectedRows...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息