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

The reason it's EMail and not Email or email in Power Automate

Explains why SharePoint's email field is spelled EMail and why the casing breaks your filters

9 hours ago

Power Automate vs Click2Export: Which Is Better to Export Reports in Dynamics 365?

Organizations using Dynamics 365 often need more than just workflow automation. They need a reliable way to export reports, generate documents...

6 days ago

Microsoft Power Automate – Run Python scripts using current Python versions in desktop flows

We are announcing the ability to run Python scripts using current Python versions in desktop flows in Microsoft Power Automate. This feature w...

7 days ago

Microsoft Power Automate – Connect to local AI models from desktop flows

We are announcing the ability to connect to local AI models from desktop flows in Microsoft Power Automate. This feature will reach public pre...

7 days ago

Power Automate – Enable Process Intelligence Experience in object-centric process mining

We are announcing the availability of Process Intelligence Experience in object-centric process mining in Power Automate Process Mining. This ...

7 days ago

Dataverse Plugins vs Power Automate: What Microsoft Experts Actually Use in Real Projects

Introduction One of the most common questions I hear from Power Platform developers and Dynamics 365 professionals is: “Should I use a D...

8 days ago

Power Automate| AZ Key Vault | 403 firewall error

💡 Power Platform  ·  Azure Key Vault Fix “Connector IP Not Authorized”in Azure Key Vault + Power Automate A...

8 days ago

Microsoft Purview | Data Lifecycle Management – Power Automate integration with records management

Microsoft Purview Records Management will integrate with Power Automate to enable custom workflows when retention-labeled items reach the end ...

9 days ago

Microsoft Power Automate – Measure time and cost savings for desktop flows

We are announcing the ability to measure time and cost savings for desktop flows in Microsoft Power Automate. This feature will reach general ...

14 days ago

How to stop an infinite trigger loop in Power Automate?

Stop a flow from re-triggering itself with trigger conditions, flag columns, or a create-only trigger.

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