Purpose:
Demonstrates how can get the last workflow approver for purchase orders in X++.
Application:
Dynamics 365 for Finance and Operations
Business requirement:
Get the last workflow approver for purchase orders in X++.
Solution:
We can use the code below to get the last workflow approver for purchase orders. The code extends PurchTable table to add a method to get the last workflow approver.
Code
[ExtensionOf(tableStr(PurchTable))]
internal final class MK_PurchTable_Extension
{
/// <summary>
/// Gets the last workflow approver.
/// </summary>
/// <remarks>Muhammad Anas Khan</remarks>
public UserId getLastWorkflowApprover()
{
WorkflowTrackingStatusTable workflowTrackingStatusTable;
WorkflowTrackingTable workflowTrackingTable;
UserInfo userInfo;
UserId ret;
select firstonly workflowTrackingTable
join workflowTrackingStatusTable
where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
&& workflowTrackingStatusTable.ContextTableId == this.TableId
&& workflowTrackingStatusTable.ContextRecId == this.RecId
&& workflowTrackingTable.TrackingType == WorkflowTrackingType::Approval
join userInfo
where workflowTrackingTable.User == userInfo.id;
if (workflowTrackingTable.RecId)
{
ret = userInfo.id;
}
return ret;
}
}