Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

Workflow in code - Multiple actions

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();
        }
    }
}
  • 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
    Anton Venter 18,561 Super User 2024 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,572 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,706 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans