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

Power Automate: parseDateTime function

Converts a date string into an ISO 8601 timestamp using a locale and optional format. Locale comes second.

12 hours ago

Power Automate – Improved Power Automate licensing dashboard

We are announcing an improved licensing dashboard in Power Automate. This feature will reach general availability on August 30, 2026. How does...

4 days ago

Microsoft Power Automate – Create and visualize custom KPIs in the process intelligence experience

We are announcing the ability to create and visualize custom KPIs in the process intelligence experience in Microsoft Power Automate. This fea...

4 days ago

Microsoft Power Automate – Create and visualize custom KPIs in the process intelligence experience

We are announcing the ability to create and visualize custom KPIs in the process intelligence experience in Microsoft Power Automate. This fea...

4 days ago

Creating AI-Powered Workflows Using Power Automate and Azure AI

Introduction Artificial Intelligence is revolutionising business automation by enabling organisations to build workflows that not only automat...

4 days ago

Power Automate: Office 365 Outlook - Get emails Action

Returns an array of emails from a mailbox folder. Filter fields only scan the first 250 emails.

6 days ago

Power Automate: convertTimeZone function

Converts a timestamp between two time zones, daylight saving included. Output drops the zone marker.

7 days ago

Power Automate mobile apps, the Excel add-in and personal accounts are going away

Power Automate is dropping the mobile app, the Excel add-in and personal accounts. What changes and when.

7 days ago

Dynamics 365 CE vs Finance & Operations: Which Microsoft Dynamics 365 Career Path Should You Choose in 2026?

Introduction Microsoft Dynamics 365 is one of the world’s leading enterprise business application platforms, offering specialized soluti...

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