web
You’re offline. This is a read only version of the page.
close
Skip to main content
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();
        }
    }
}
I have the same question (0)
  • Jonas "Jones" Melgaard Profile Picture
    4,889 Super User 2025 Season 2 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,229 Super User 2025 Season 2 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 886 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 870 Super User 2025 Season 2

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 697

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans