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
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 ...
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.
25 Power Automate Flows That Can Save You 10 Hours Every Week
Introduction Imagine arriving at work on Monday morning and discovering that most of your repetitive tasks have already been completed automat...
Open a Power Automate Flow for Edit Without Fixing Broken Connections First
While reviewing Power Automate flows recently, we ran into an issue where we could not open a flow in edit mode When opening the flow, Power A...
Why Power Automate Isn't the Answer to Record Cloning in Dynamics 365
Your Dynamics 365 team isn't slow. They're just copying the wrong way. The native duplicate feature in Dynamics 365 was never designed for rea...
Trigger a flow when a Power Automate Approval is complete (Accepted or Rejected)
Stop waiting on approvals—trigger a flow the moment a decision is made The post shows how to trigger a Power Automate flow when an Power Auto...
How to get my Power Automate to run more than 30 days?
Redesign Flows that need to wait past 30 days: log requests and process them on a schedule.
Microsoft Power Automate – Export object-centric process mining data to Microsoft Fabric semantic model
We are announcing the ability to export object-centric process mining data to Microsoft Fabric semantic model in Microsoft Power Automate. Thi...
Microsoft Power Automate – Configure notifications for desktop flow checker in admin portal
We are announcing the ability to configure notifications for the desktop flow checker in the admin portal in Microsoft Power Automate. This fe...
Power Automate – View property value expanded inline in the new cloud flow designer
We are announcing the ability to view property value expanded inline in the new cloud flow designer in Power Automate. This feature will reach...