【自动下推二开插件】设置分录下推数据和目标单据类型原创
金蝶云社区-zlz
zlz
18人赞赏了该文章 2,410次浏览 未经作者许可,禁止转载编辑于2023年02月09日 16:23:03

【官方知识】:

 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);
}


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

图片.png

图标赞 18
18人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!

您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!

请选择打赏金币数 *

10金币20金币30金币40金币50金币60金币
可用金币: 0