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

Enable or Disable Purchase Requisition Approval Button Based on Workflow Status

Control the Purchase Requisition Approval button in D365 F&O using X++ and workflow status to manage its enabled or disabled state.

Ahmad Hassan

Ahmad Hassan

Dynamics 365 F&O Consultant

Share
Enable or Disable Purchase Requisition Approval Button Based on Workflow Status

This form data source event handler controls the ApproveBtn button on the PurchReqTable form. When the data source is activated, it checks whether the current purchase requisition has a pending workflow work item. The approval button is enabled when pending work exists and disabled when no pending work item is found.

X++ Code

[FormDataSourceEventHandler(formDataSourceStr(PurchReqTable, PurchReqTable), FormDataSourceEventType::Activated)]
public static void PurchReqTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
    FormRun formRun = sender.formRun();
    FormButtonControl approvedButton = formRun.design().controlName("ApproveBtn");
    PurchReqTable purchReqTable = sender.cursor();

    if (ED_WorkflowHelperApproveReject::hasPendingWorkItem(purchReqTable))
    {
        approvedButton.enabled(true);
    }
    else
    {
        approvedButton.enabled(false);
    }
}

Process Flow

When the PurchReqTable data source is activated, the handler gets the current form and purchase requisition record.

It locates the ApproveBtn control and checks the current requisition using ED_WorkflowHelperApproveReject::hasPendingWorkItem().

If a pending workflow work item exists, the approval button is enabled.

Otherwise, the approval button is disabled.

b972797c-5b6c-442b-94c8-9013743972ba.png

Figure: Flow of controlling the purchase requisition approval button based on pending workflow work items.

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