Skip to content

Instantly share code, notes, and snippets.

@jofme
Last active October 12, 2024 16:12
Show Gist options
  • Select an option

  • Save jofme/76effa3bb1a6ce06c2751721091fb9bb to your computer and use it in GitHub Desktop.

Select an option

Save jofme/76effa3bb1a6ce06c2751721091fb9bb to your computer and use it in GitHub Desktop.
wfBulkDelegation
void clicked()
{
WorkFlowWorkItemTable workItem, workItemUpdate, workItemSend;
MultiSelectionHelper helper;
WorkflowWorkItemActionDialog workflowWorkItemActionDialog;
// Initialization of attributes
helper = MultiSelectionHelper::construct();
helper.parmDatasource(workflowWorkItemTable_ds);
workItem = helper.getFirst();
// Dialog execution
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 the status is changed to Returned inside the 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
);
// Update the record
ttsBegin;
select forUpdate workItemUpdate
where workItemUpdate.RecId == workItem.RecId;
workItemUpdate.Status = WorkFlowWorkItemStatus::Completed;
workItemUpdate.update();
ttsCommit;
}
catch (Exception::Error)
{
throw error(strfmt("Error in the bulk action"));
}
workItem = helper.getNext();
}
info("Bulk delegation completed");
// Refresh the DataSource
workflowWorkItemTable_ds.research();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment