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 moreRelated posts
Power Automate Retry and Error Handling Patterns for Reliable Power Pages Integrations
When Power Pages integrates with Power Automate, reliability becomes key. Portal users expect instant responses — whether submitting a form, u...
Handling Large Files in Power Automate
Power Automate can handle large files, but how large? SharePoint Online supports files up to 250 GB, which sounds generous until you try movin...
UTCNow and that little hidden feature in Power Automate
If you have been following my posts on SharePains.com, then you will know about the UTCNow function generating the current UTC time. But did y...
Understanding Binary and Base64 in Power Automate
If you work with Power Automate and deal with files, you’ve encountered issues saving them. If you see things like “String/bytes i...
How to Auto-Fill Third-Party Web Forms Using Power Automate Desktop and JavaScript
In today’s digital workflows, teams across HR, operations, finance, and support deal with repetitive manual tasks every day. One of the most c...
How to Design Custom Approval Buttons in Outlook Email Using Power Automate (Step-by-Step Guide)
Microsoft’s standard approval emails make it easy to send and capture user feedback directly through Outlook. However, one major limitation is...
We need to talk about... Power Automate... Licensing
Next in my blog, I am going to cover a topic that has come up several times in recent conversations with clients.....Microsoft Licensing! part...
Flows getting triggered multiple times / missing callbackregistration record – Power Automate / Dataverse
Recently, we observed that one of our flows was getting triggered multiple times in our UAT environment; however, the flow was working properl...
Power Automate – Information about ‘Retry with AI vision’ functionality in Power Automate for desktop
We are announcing the introduction of the Retry with AI vision feature in error handling for UI and browser automation within Power Automate f...
How to Automate Post-Case Resolution Surveys in Dynamics 365 with Copilot and Power Automate (Preview)
Exceptional customer service doesn’t end when a support ticket is closed. In many cases, the most insightful feedback comes after the re...