Skip to main content

Notifications

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,631 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

News and Announcements

Give Back to the Community this Month

Quick Links

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,133 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,154

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans