Loading...

Play around with D365FO workflow .. Some code samples to

Play around with D365FO workflow ..  Some code samples to

 1. Current workflow User a  by code 

public WorkflowUser currentWFUser(Common _common)

    {

        WorkflowTrackingStatusTable workflowTrackingStatusTable;

        WorkflowTrackingTable       workflowTrackingTable; 

        

        select firstonly RecId from workflowTrackingStatusTable

            join User from workflowTrackingTable

            order by WorkflowTrackingTable.CreatedDateTime desc

            where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId

            && workflowTrackingStatusTable.ContextRecId             == _common.RecId

            && workflowTrackingStatusTable.ContextTableId           == _common.TableId

            && workflowTrackingTable.TrackingContext                == WorkflowTrackingContext::WorkItem;


        return workflowTrackingTable.User;

    }

2. Approve a workflow by code

public void autoApproveWF(Common _common, str _user)

    {

        WorkflowWorkItemTable WorkflowWorkItemTable;


        select WorkflowWorkItemTable

            where  workflowWorkItemTable.Type   == WorkflowWorkItemType::WorkItem

            &&  workflowWorkItemTable.Status    == WorkflowWorkItemStatus::Pending

            &&  WorkflowWorkItemTable.RefTableId== _common.TableId

            &&  WorkflowWorkItemTable.RefRecId  ==  _common.RecId;


        WorkflowWorkItemActionManager::dispatchWorkItemAction(

                                WorkflowWorkItemTable,

                                "Auto Approve by system",

                                _user,

                                WorkflowWorkItemActionType::Complete,

                                menuitemDisplayStr(PurchReqTable)); 

    }


3, Display approver name

 display WorkflowApprovalName Displayapprovername()

    {

        WorkflowTrackingStatusTable workflowTrackingStatusTable;

        WorkflowTrackingTable WorkflowTrackingTable;

        WorkflowApprovalName approvername;


        select firstonly workflowtrackingstatustable

            join workflowtrackingtable

           where workflowtrackingstatustable.ContextRecId == this.recid

            && workflowtrackingtable.TrackingContext == workflowtrackingcontext::WorkItem

            && workflowtrackingtable.TrackingType == workflowtrackingtype::Approval

            && workflowtrackingtable.WorkflowTrackingStatusTable == workflowtrackingstatustable .recid;

        {

            approvername = workflowtrackingtable.User;

        }

        return approvername;

    }

    4. Get last approver name for PO by PurchID


     select firstFast _PURCHTABLE where _PURCHTABLE.PurchId == purchTable.PurchId ;

            select firstFast _WorkflowTrackingStatusTable

             order by _WorkflowTrackingStatusTable.RecId desc

             where _WorkflowTrackingStatusTable.ContextRecId == _PURCHTABLE.RecId  && _WorkflowTrackingStatusTable.ContextCompanyId == curext()

                          && _WorkflowTrackingStatusTable.TrackingStatus == WorkflowTrackingStatus::Completed ;

            select _WorkflowTrackingTable

                    order by _WorkflowTrackingTable.createdDateTime desc

                   where _WorkflowTrackingTable.WorkflowTrackingStatusTable == _WorkflowTrackingStatusTable.RecId

                && _WorkflowTrackingTable.TrackingType == 4 ;


Published on:

Learn more
Sherif Fayed
Sherif Fayed

Share post:

Related posts

Copy and Paste in Power Automate Classic vs New UI

Copy and Paste has existed for a while in the classic Power Automate UI. With the new UI however there are a few additional features in this a...

2 hours ago

Implement Service-based integration in D365FO

This blog post describes how to implement a synchronous integration with D365FO by creating a service using the External Integration framework...

16 hours ago

Power Automate: Retiring the Impala connector

The Impala connector will be retired and removed from Copilot Studio, Logic Apps, Power Apps, and Power Automate between April 1-14, 2026. Exi...

1 day ago

Power Automate: Get support for normalized schema import for data ingestion

Customers with existing data pipelines or data products in data mesh mostly want to stick to normalized, efficient forms such as star schema. ...

7 days ago

Power Automate: Export object-centric process mining data to Microsoft Fabric semantic model

Publishing to Microsoft Fabric breaks down data silos and amplifies the impact of your process insights across your organization. Instead of k...

7 days ago

Power Automate: Create and visualize custom KPIs in Process Intelligence Studio

Custom KPIs put your unique business priorities at the center of process analysis. While standard metrics provide valuable baseline insights, ...

7 days ago

Power Automate: Analyze your processes in Process Intelligence Studio

Process Intelligence Studio eliminates the friction between your questions and your answers. Instead of navigating rigid dashboards or using a...

7 days ago

Power Automate: Configure Entra hybrid join for hosted machine groups

Microsoft Entra hybrid join with custom virtual networks (VNETs) and hosted machine groups lets your hosted machine group bots enroll in both ...

7 days ago

Power Automate: Enable version control for desktop flows

With version control in Power Automate for desktop, you can see what changes were made and who made them. This feature makes it easier to debu...

7 days ago

Power Automate: Use Power Platform environment variables in desktop flows

Retrieve Power Platform environment variables directly through their desktop flows without the need to pass them as inputs to the flow. A new ...

7 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy