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
New Approved Customer List mapping for Items in Dynamics 365 Finance and operations
Take control of your sales process with the latest feature in Microsoft Dynamics 365 Finance – the Approved Customer List! This powerful new f...
Part-9: Connect and Query Dynamics 365 Finance and operations data with Copilot studio
In this video, we kick off an exciting new series focused on extending Copilot Studio capabilities by connecting it to real enterprise data! �...
Part-5:Calling Power Automate with Microsoft Copilot
🚀 How to Use Power Automate Flows in Microsoft Copilot Studio | Hands-On Guide 🎥 In this episode of my Microsoft Copilot Studio series,...
Track Time and Cost Savings with Power Automate’s New “Savings” (Preview) Feature
While creating a Power Automate flow, I discovered an exciting new feature called the “Savings” (Preview) feature in Power Automate. When I tr...
Announcing major DLP enhancements for Power Automate and Copilot Studio
DLP (Data Loss Prevention) for Power Automate enables administrators to manage data access from both cloud and desktop Power Automate flows, a...
Power Automate: Running PowerShell Scripts
Many things can be done in Power Automate or using Microsoft Graph, but not everything. For certain things, Microsoft requires us to use Power...
Microsoft Power Automate – Testing framework for desktop flows
We are announcing a testing framework for desktop flows in Microsoft Power Automate for desktop. This feature will reach general availability ...