Purpose:
Demonstrate how can we get the user, the workflow is assigned to, for purchase orders in X++.
Application:
Dynamics 365 for Finance and Operations
Business requirement:
Get the user, the workflow is assigned to, for purchase orders.
Solution:
We can use the code below to get the user, the workflow is assigned to, for purchase orders. The following code is an event handler for Inserted event on table WorkflowWorkItemTable. The code takes the assignee User Id and saves it in the extension table.
Code
/// <summary>
/// Defaults assignee to purchase order extension table.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(WorkflowWorkItemTable), DataEventType::Inserted)]
public static void WorkflowWorkItemTable_onInserted(Common sender, DataEventArgs e)
{
WorkflowWorkItemTable workflowWorkItemTable;
ATLAS_PurchTableExtended purchTableExtended;
PurchTable purchTable;
workflowWorkItemTable = sender as WorkflowWorkItemTable;
if (workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem)
{
if (workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending)
{
if (workflowWorkItemTable.RefTableId == tableNum(PurchTable))
{
if (workflowWorkItemTable.CompanyId)
{
changecompany(workflowWorkItemTable.CompanyId)
{
purchTable = PurchTable::findRecId(workflowWorkItemTable.RefRecId, true);
purchTableExtended = ATLAS_PurchTableExtended::find(purchTable.RecId, true);
if (purchTableExtended)
{
try
{
ttsbegin;
purchTableExtended.PurchAssignee = workflowWorkItemTable.UserId;
purchTableExtended.update();
ttscommit;
}
catch (Exception::Error)
{
error(strFmt("@ATLAS:ErrorWhileDefaultingAssignee"));
}
}
}
}
}
}
}
}