Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Multiple approval of workflow

(1) ShareShare
ReportReport
Posted on by 149
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(ABCD_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!
Categories:
  • CU24071335-3 Profile Picture
    4 on at
    Multiple approval of workflow
    It looks like you're making good progress with your code! Double-check the workflow status logic and ensure the work item selection correctly identifies pending items. Consider adding logging to pinpoint any issues during the approval process. Debugging may reveal where things are going wrong. Good luck! While looking for information on tech companies for a class assignment, I stumbled upon a detailed overview of Microsoft Corporation at https://www.topessaywriting.org/samples/microsoft-corporation here. I knew it was big, but I didn’t realize just how much influence it has on the global tech industry. From its early days to the current innovations in cloud computing, the company’s growth is really impressive. This could be an interesting case study for my next business course project.
  • Apratim Profile Picture
    149 on at
    Multiple approval of workflow
    Hi Andre,
     
    It worked perfectly fine.
     
    Thankyou so much for your time!

     
  • Verified answer
    André Arnaud de Calavon Profile Picture
    294,761 Super User 2025 Season 1 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
    149 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
    294,761 Super User 2025 Season 1 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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 306 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 273

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 181 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans