Skip to main content

Notifications

Community site session details

Community site session details

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

Workflow in code - Multiple actions

(1) ShareShare
ReportReport
Posted on by 2
The objetive of this code is to take the same actions in multiple WorkFlowWorkItems, for example:
  •  approve several purchase requisitions at the same time.   
 
I´m trying to make a massive approval using the "WorkflowWorkItemActionManager" class. However there is an issue. 
 
 
 
This is my code: 
 
void clicked()
{
    WorkFlowWorkItemTable               workItem, workItemUpdate, workItemSend;
    MultiSelectionHelper                helper;
    WorkflowWorkItemActionDialog        workflowWorkItemActionDialog;
    //Inicialización de atributos
    helper = MultiSelectionHelper::construct();
    helper.parmDatasource(workflowWorkItemTable_ds);
    workItem = helper.getFirst();
    //Ejecución dialogo
    if (workItem.RecId != 0)
    {
        workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct(workItem,
                                                                                    WorkflowWorkItemActionType::Delegate,
                                                                                    new MenuFunction(menuitemActionStr(WorkflowLineItemResubmit), MenuItemType::Display));
        workflowWorkItemActionDialog.run();
        if (workflowWorkItemActionDialog.parmIsClosedOK())
        {
            // Condition is Rejected because Status is changed in Returned inside Approval Event Handler.
            while (workItem.RecId != 0 && workItem.Status == WorkFlowWorkItemStatus::Pending)
            {
                select firstOnly workItemSend
                    where workItemSend.RecId == workItem.RecId;
                try
                {
                    WorkflowWorkItemActionManager::dispatchWorkItemAction(workItemSend,
                                                                    workflowWorkItemActionDialog.parmWorkflowComment(),
                                                                    workflowWorkItemActionDialog.parmTargetUser(),
                                                                    WorkflowWorkItemActionType::Delegate,
                                                                    menuItemDisplayStr(WorkflowWorkListAcceptanceMassive),false);
                    //Actualizamos el registro
                    ttsBegin;
                    select forUpdate workItemUpdate where workItemUpdate.RecId == workItem.RecId;
                    workItemUpdate.Status = WorkFlowWorkItemStatus::Completed;
                    workItemUpdate.update();
                    ttsCommit;
                }
                catch(Exception::Error)
                {
                    throw error(strfmt("Error en la acción masiva"));
                }
                workItem = helper.getNext();
            }
            info("Delegación masiva finalizada");
            // Refrescar el DataSource
            workflowWorkItemTable_ds.research();
        }
    }
}
  • Jonas "Jones" Melgaard Profile Picture
    4,419 Super User 2025 Season 1 on at
    Workflow in code - Multiple actions
    Yep, I agree. Can you run the application in English also?
     
    I have tried to use ChatGPT to translate the labels, hope this makes sense (-:
  • Anton Venter Profile Picture
    20,036 Super User 2025 Season 1 on at
    Workflow in code - Multiple actions
    What is the issue? Please translate to English and add your code using the "Insert code snippet" button, it makes it easier to read :-).

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans