Skip to main content

Notifications

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();
        }
    }
}
  • 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,788 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

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans