Delegation to another user of your workflow items in D365FO / AX
I need to reassign a work item from one user to another because the original user who was assigned the task has left the company. The client also requires that we track the workflow history as we reassign the work item.
Final class NGDelegateWorkFlowJob
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
PurchTable purchTable;
HcmJob hcmJob;
WorkflowWorkItemTable workflowWorkItemTable;
WorkflowWorkItemActionType actionType;
WorkflowUser workflowUser;
String255 userID;
str menuItemName;
WorkflowWorkItemComment workflowWorkItemComment;
VendInvoiceInfoTable VendInvoiceInfoTable;
System.Exception exception;
#OCCRetryCount
try
{
// VendInvoiceInfoTable = VendInvoiceInfoTable::findPurchId("");
hcmJob = hcmJob::findByJob("Finaltest3");
select firstonly workflowWorkItemTable
order by RecId desc
where workflowWorkItemTable.RefTableId == tableNum(HcmJob) //tableNum(VendInvoiceInfoTable)
&& workflowWorkItemTable.RefRecId == hcmJob.recid // VendInvoiceInfoTable.recid
&& workflowWorkItemTable.Status == WorkFlowWorkItemStatus::Pending
&& workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem
&& workflowWorkItemTable.UserId == "abc"; // Leon
if (workflowWorkItemTable)
{
workflowUser = "Admin"; // Those user ide which you need to modified
workflowWorkItemComment = "delegate the workitem as old user doesnot exists";
ttsbegin;
workflowWorkItemTable.selectForUpdate(true);
WorkflowWorkItem::delegateWorkItem(workflowWorkItemTable.Id, workflowUser , workflowWorkItemComment);
ttscommit;
}
Info("workitem delegation done");
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if(appl.ttsLevel() == 0)
{
if(xSession::currentRetryCount() >= #RetryNum)
{
throw exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw exception::UpdateConflict;
}
}
catch (Exception::Error)
{
throw error("Error occurred.");
}
}
}
Comments
Post a Comment