首页 > 其他分享 >D365: Workflow避免同一审核人多次审批(问题处理2:审批人拒绝,重新提交后,审批流直接流转到拒绝人节点)

D365: Workflow避免同一审核人多次审批(问题处理2:审批人拒绝,重新提交后,审批流直接流转到拒绝人节点)

时间:2022-11-02 15:59:53浏览次数:63  
标签:workItems WorkflowWorkItemTable Workflow 拒绝 workItemActivityContext 审批 workItemT

前面提到过,当审批人出现在多个节点,前面的节点审批完成后,后面节点如果再次出现同一审批人,系统自动审批,在测试中发现另外一种场景,当审批流执行了多个节点后,中间节点的某个审批人拒绝了提交的单据,当用户再次提交审批流后,系统会出现新的bug,由于我们改过的逻辑,当审批流的工作项中出现了完成的记录,系统会自动跳过或者审批后创建的节点,这里没有考虑拒绝的情况,经过调查,按下面方法修复了此问题,修复后也解决了审批人拒绝,重新提交后,审批流直接流转到拒绝人节点,这个也是标准功能存在的缺陷。

代码也很简单,在处理工作项时,只需要加一个判断,判断当前的工作项的类型是否是WorkflowWorkItemType::WorkItem。

public static void removeWorkItems(WorkItemActivityContextCollection _workItems)
    {
        Microsoft.Dynamics.AX.Framework.Workflow.Runtime.WorkItemActivityContext workItemActivityContext;
        System.Collections.IEnumerator enumerator;
        WorkflowWorkItemTable          workItemTable;
        WorkflowStepTable              workflowStepTable;
        int                            i;
        Array                           array;
        boolean  skip;
        
        next removeWorkItems(_workItems);

        for (i = 0; i < _workItems.Count; i++)
        {
            workItemActivityContext = _workItems.get_ITEM(i);
            skip = SysWorkflowWorkItemHelper::skipWorkItem(workItemActivityContext);
            if (skip)
            {
                if (_workItems.Count == 1)
                {

                    workItemTable   = WorkflowWorkItemTable::findActivityInstanceId(workItemActivityContext.get_ActivityId());
                    
                    if (workItemTable.RecId == 0)
                    {
                        new SysWorkflowWorkItem().callCreateWorkItems(workItemActivityContext, NoYes::Yes);
                    }
                    workItemTable   = WorkflowWorkItemTable::findActivityInstanceId(workItemActivityContext.get_ActivityId());
                    
                    if (workItemTable)
                    {
                        if (workItemTable.Type == WorkflowWorkItemType::WorkItem)
                        {
                            WorkflowWorkItemActionManager::dispatchWorkItemAction(
                                    workItemTable,
                                    "Auto Approve",
                                    workItemTable.UserId,
                                    WorkflowWorkItemActionType::Complete,
                                    workItemTable.MenuItemName);
                        }
                    }
                }
                else
                {
                    workflowStepTable   = WorkflowStepTable::find(workItemActivityContext.StepActivityId);
                    if (workflowStepTable.CompletionPolicy == WorkflowStepCompletionPolicy::Single)
                    {
                        _workItems.Remove(workItemActivityContext);
                    }
                    else
                    {
                        workItemTable   = WorkflowWorkItemTable::findActivityInstanceId(workItemActivityContext.get_ActivityId());
                    
                        if (workItemTable.RecId == 0)
                        {
                            new SysWorkflowWorkItem().callCreateWorkItems(workItemActivityContext, NoYes::Yes);
                        }
                        workItemTable   = WorkflowWorkItemTable::findActivityInstanceId(workItemActivityContext.get_ActivityId());
                    
                        if (workItemTable)
                        {
                            if (workItemTable.Type == WorkflowWorkItemType::WorkItem)
                            {
                                WorkflowWorkItemActionManager::dispatchWorkItemAction(
                                    workItemTable,
                                    "Auto Approve",
                                    workItemTable.UserId,
                                    WorkflowWorkItemActionType::Complete,
                                    workItemTable.MenuItemName);
                            }
                        }
                    }
                }
            }
        }
        
    }

 

标签:workItems,WorkflowWorkItemTable,Workflow,拒绝,workItemActivityContext,审批,workItemT
From: https://www.cnblogs.com/dingkui/p/16851219.html

相关文章