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;



                                "Auto Approve by system",





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

Easiest Power Automate Sequential Approval Flow Pattern

With a Power Automate sequential approval you can use a single approval action to send ... The post Easiest Power Automate Sequential Approval...

22 hours ago

Exploring Access Management using Power Automate Flows in Dynamics 365

In Dynamics, managing access to sensitive data is handled through security measures such as role-based permissions. Security roles and access ...

5 days ago

Dynamics 365 Business Central: How to Copy Existing Customer to New Customer with Power Automate (Copy Customer)

Hi, Readers.Today I would like to talk about how to copy Existing Customer to New Customer with Power Automate. This is a problem I’ve seen in...

6 days ago

Fixed – Action Failed: A record with matching key values already exists (DuplicateRecord)– Power Automate / Dataverse

Recently while testing one of our old existing flows, we got the below error Action ‘Create_BOQ_Log_Record’ failed: A record with ...

7 days ago

Dynamics 365 Business Central: How to set dimension via standard API and Can we do it via Power Automate?

Hi, Readers.Today I would like to briefly talk about how to set dimension via standard API and can we do it in Power Automate?Dimensions are v...

7 days ago

Send An Approval To A Microsoft 365 Group In Power Automate

An approval can be sent to a Microsoft 365 group in Power Automate. You can ... The post Send An Approval To A Microsoft 365 Group In Power Au...

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