Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Multiple approval of workflow

Posted on by 143
Hi Community,

I have a requirement where I need to approve multiple lines in LedgerPeriodCloseProjectTask table at once using the Approval button in Workflow.
I also wrote a code for submitting a multiple records to workflow which is working fine!
The issue is in Approval. Its not Approving even after the Workflowstatus of the Line changes to approve! When I check the View history button in workflow its shows as it is still pending! 

Sharing my code snippet:
class ABCD_CloseTaskWorkflowTypeApprovalManager
{
    public static void main(Args args)
    {
        //  TODO:  Write code to execute once a work item is submitted.
        FormDataSource                  periodClosetask_ds;
        LedgerPeriodCloseProjectTask    customWorkflowTable;
        WorkflowWorkItemTable           workflowWorkItemTable;
        WorkflowComment                 note = "";
        WorkflowSubmitDialog            workflowSubmitDialog;
        WorkflowCorrelationId           workflowCorrelationId;

        //multiSelectHelper       =       MultiSelectionHelper::construct();
        periodClosetask_ds      =       FormDataUtil::getFormDataSource(args.record());

        WorkflowTypeName        workflowTypeName = workFlowTypeStr("ABCD_CLoseTaskWorkflowType");

        //Opens the submit to workflow dialog.
        if (periodClosetask_ds.anyMarked())
        {
            customWorkflowTable = args.record();
            // Get comments from the submit to workflow dialog.
            note = "Note check !";

            for(customWorkflowTable = periodClosetask_ds.getFirst(true)? periodClosetask_ds.getFirst(true) : periodClosetask_ds.cursor();customWorkflowTable;customWorkflowTable = periodClosetask_ds.getNext())
            {
                try
                {
                    if (customWorkflowTable.ABCD_WorkFlowStatus == ABCD_CloseTaskWorkFlowStatus::Submitted)
                    {
                        select firstonly workflowWorkItemTable
                            where workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem
                            && workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending // this should be Pending
                            && WorkflowWorkItemTable.RefTableId == tableNum(LedgerPeriodCloseProjectTask)
                            && WorkflowWorkItemTable.RefRecId  == customWorkflowTable.RecId;

                        WorkflowWorkItemActionManager::dispatchWorkItemAction(workflowWorkItemTable,note,curUserId(),WorkflowWorkItemActionType::Complete,menuItemActionStr(ADCG_CloseTaskWorkflowApprovalApprove),"WorkflowApproval");
                    }
                }
                catch (Exception::Error)
                {
                    error("Error on workflow Approval !");

                }
            }
        }

        periodClosetask_ds.reread();
        periodClosetask_ds.research(true);
        periodClosetask_ds.refresh();
    }

}
Please help me out as this is urgent!
Thanks in advance!
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,584 Super User on at
    Multiple approval of workflow
    Hi Apratim,
     
    You can try to build the dialog with this example.
     
    
    Dialog dialog;
    DialogField field;
    ;
    dialog = new Dialog("Workflow comment");
    dialog.addText("PLease provide a comment for the workflow approval");
    field = dialog.addField(typeid(Notes));
    
    dialog.run();
    if (dialog.closedOk())
    {
        note = field.value();
    }
     
     
  • Apratim Profile Picture
    Apratim 143 on at
    Multiple approval of workflow
    Hi Andre,

    Thankyou so much for the reply!

    I checked the code after debugging! It was having the record for the selected lines for approval as an event in EVENTINBOXDATA table. 
    This was due to my mistake as I was changing the Approval status manually from approved to Draft using SSMS for testing purpose!
    As per the code its working fine!

    If possible can you help me in bringing the Workflow comment dialog box too; So that the user can put their custom comment once and that comment should be passed in the approval of all selected tasks ! Since for now as you can see I'm passing a hardcode comment while Approving the workflow for all the selected tasks  for approval!

    Thanks once again!!

     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,584 Super User on at
    Multiple approval of workflow
    Hi Apratim,
     
    Did you use the debugger to find out what is being executed? What is the "Line" where the workflow status is changing? Is it the workflow work item or the LedgerPeriodCloseProjectTask?
    Note that in case approval is recorded by a user manually, the workflow processing batch job will pick up the change and process the instance using the next step in the workflow state engine.
    Probably after your code was executed, the batch job should do its work to complete it correctly.
     
    A small additional note about your urgency. This is a forum monitored by volunteers in their spare time. It is a hobby for me to help people with questions and issues. This is not a support channel with a specific SLA.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans