Skip to main content

Notifications

Announcements

No record found.

D365FO: Get last workflow approver for purchase orders in X++

Purpose:

In this post we’re going to see how can we get last workflow approver for purchase orders in X++.

Application:

Dynamics 365 for Finance and Operations.

Business requirement:

Get the last purchase order approver in X++.

Solution:

Please use the code below to get the last purchase order approver.

Tip:

Take a note that workflow tables are cross-company tables. That’s why it is important to change company when making joins with them, else you will get empty table buffers!

Code

/// <summary>
/// Gets workflow last approver for purchase orders.
/// </summary>
public void getPurchWorkflowApprovers()
{
	WorkflowTrackingStatusTable workflowTrackingStatusTable;
	WorkflowTrackingTable workflowTrackingTable;
	PurchTable purchTable;
	PurchTable purchTableWTT;

	while select crosscompany purchTable
	{
		changecompany(purchTable.DataAreaId)
		{
			select firstonly crosscompany workflowTrackingTable
				order by workflowTrackingTable.RecId desc
				join workflowTrackingStatusTable
					where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
				join purchTableWTT
					where workflowTrackingStatusTable.ContextTableId == tableNum(PurchTable)
						&& workflowTrackingStatusTable.ContextCompanyId == purchTableWTT.DataAreaId
						&& workflowTrackingStatusTable.ContextRecId == purchTableWTT.RecId
						&& workflowTrackingTable.TrackingContext == workflowtrackingcontext::WorkItem
						&& workflowTrackingTable.TrackingType == workflowtrackingtype::Approval
						&& purchTableWTT.RecId == purchTable.RecId;
			
			info(strFmt("%1, %2", purchTable.PurchId, workflowTrackingTable.User));
		}
	}
}

Comments

*This post is locked for comments