Skip to main content
X++ Development · · 1 min read

Check Pending Workflow Work Item for Purchase Requisition

Check pending Purchase Requisition workflow work items in D365 F&O using X++ to identify approval status and support workflow processing.

Ahmad Hassan

Ahmad Hassan

Dynamics 365 F&O Consultant

Share
Check Pending Workflow Work Item for Purchase Requisition

This method checks whether the specified PurchReqTable record has a pending workflow work item assigned to the current user. It searches WorkflowWorkItemTable using the purchase requisition table and record references, pending status, and current user ID. The method returns true when a matching work item exists; otherwise, it returns false.

X++ Code

public static boolean hasPendingWorkItem(PurchReqTable _purchReqTable)
    {
        WorkflowWorkItemTable workItem;
        select firstOnly RecId from workItem
            where workItem.RefTableId == tableNum(PurchReqTable)
&& workItem.RefRecId   == _purchReqTable.RecId
&& workItem.Status     == WorkflowWorkItemStatus::Pending
&& workItem.UserId     == curUserId();

        return (workItem.RecId != 0);
    }

Process Flow

The method receives a PurchReqTable record and searches WorkflowWorkItemTable for a matching work item.

The query checks the purchase requisition table ID, record ID, pending workflow status, and current user ID.

If a matching work item is found, its RecId is non-zero and the method returns true.

If no matching work item exists, the method returns false.

7baf8b9b-cbda-4095-bda8-f9d2244368d4.png

Figure: Flow of checking a pending workflow work item for a purchase requisition and current user.

Found this useful?

Share it with your network

Ahmad Hassan

Written by

Ahmad Hassan

Microsoft Dynamics 365 & Power Platform blogger.

More about me

Related Posts

Comments

Leave a comment