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
5 fundamental Power Automate ideas that will make your flows better!
It's time to have a look at some of my older posts. In this post I'm going to have another look at these Power Automate ideas. Back in 2017/20...
Replace the Excel Online connector with the Microsoft Graph API in Power Automate
If you have worked with the Excel Online connector in Power Automate then you will most likely know the pains of this connector. In this post ...
How to Automate Formula Writing in Power Automate Using Copilot
As developers, we use Power Automate to handle everyday tasks and automate small parts of our work. Flows help reduce manual effort, improve a...
Data Retention Strategy in Power Pages – Automated Archival with Scheduled Power Automate Jobs
As Power Pages portals scale, the amount of data they generate grows exponentially—form submissions, bookings, cases, applications, event regi...
From Business Central to SharePoint: The Right Way to Save PDF Files in Power Automate
If you’re pulling PDF files from Microsoft Dynamics 365 Business Central and saving them to SharePoint using Power Automate, there’s one criti...
How to Build Environment-Aware Flows by Fetching CRM Metadata Dynamically in Power Automate
Stop relying on OData workarounds and use a professional API-based pattern instead. When building flows in Power Automate, you often need envi...
Action ‘Update_a_record’ failed: An error has occurred. No resources were found when selecting for update – Fixing Cross-Company Update Issues in Finance & Operations Using Dataverse Virtual Entities (Power Automate)
Recently, while trying to update the Projects table in Finance & Operations using the Fin & Ops Apps actions in Power Automate, we ran...
Power Automate Forward A Meeting Invite In Outlook
A Power Automate flow can forward a meeting invite to a new attendee in Outlook. ... The post Power Automate Forward A Meeting Invite In Outlo...
Power Automate Generative Actions
Power Automate Generative Actions Build Intelligent Automations with Natural Language and AI 📅 Released: Preview (2024-2025) 🎯 Status: Publi...