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

Lessons Learned in the Automation Workshop: RPA, APIs, and the Rise of CUAs

When you bring together a room full of seasoned RPA developers, a handful of API specialists, and introduce Microsoft’s vision for Computer-Us...

2 days ago

How to make your Excel connector retry in Power Automate

Last week, I came across an issue with actions failing in the Excel connector. Making try Excel Connector retry actions, was slightly harder t...

3 days ago

Power Automate - [Dataverse]

Power Automate is used to automate operations through triggers and actions.Triggers: Added, Modified, Deleted, Manual (Instant), ScheduledActi...

4 days ago

D365FO Integration: Import Purchase Orders from PDF using Gemini AI

Learn how to use AI to import purchase orders into Dynamics 365 Finance from complex PDF files. This post covers integration design, sample pr...

7 days ago

Power Automate – Analyze process mining results with a web client

The Analyze process mining results with a web client feature for Power Automate has reached general availability. This feature allows you to v...

14 days ago

Create X++ Client Plugins for Copilot Studio in Dynamics 365 F&O

Part 3 of the Copilot Studio + F&O extensibility series. Learn what client plugins are, when to use them, and how to build one in X++—fro...

16 days ago

Fixed – Flow not getting triggered / incorrect callback registration record (Power Automate / Dataverse)

Recently, we faced an interesting issue, where we updated an existing flow in our Dev, basically we removed the Filter Rows condition and depl...

16 days ago

Power Automate – Organize desktop flows using tags

We are announcing the ability to organize desktop flows using tags in Power Automate. This feature will reach general availability on Septembe...

20 days ago

Build an X++ AI Tool for Copilot Studio in Dynamics 365 F&O

Learn how to wire real F&O business logic into Copilot Studio. This guide shows you how to build an X++ AI tool, set up security, auto/ha...

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