D365: How to get workflow assignee in X++

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 following code to retrieve the user assigned to the workflow for purchase orders. This code extends the PurchTable table.

Code

[ExtensionOf(tableStr(PurchTable))]
internal final class ATLAS_PurchTable_Extension
{
	/// <summary>
    /// Gets the workflow assignee.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public UserId getWorkflowAssignee()
    {
        WorkflowTrackingStatusTable workflowTrackingStatusTable;
        WorkflowWorkItemTable workflowWorkItemTable;
        UserInfo userInfo;
        UserId ret;

        select firstonly workflowWorkItemTable
            where workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem
                && workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending
            join workflowTrackingStatusTable
                where workflowWorkItemTable.CorrelationId == workflowTrackingStatusTable.CorrelationId
                    && workflowTrackingStatusTable.ContextTableId == this.TableId
                    && workflowTrackingStatusTable.ContextRecId == this.RecId
                    && workflowTrackingStatusTable.TrackingStatus == WorkflowTrackingStatus::Pending
            join userInfo
                where workflowWorkItemTable.UserId == userInfo.id;

        if (workflowWorkItemTable.RecId)
        {
            ret = userInfo.id;
        }

        return ret;
    }
}

Leave a comment

Blog at WordPress.com.

Up ↑