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
{How to} Create a flow on a file in Teams on Power Automate
Hello Everyone,Today i am going to share my thoughts about create a flow on a file in Teams.Let's get's started.Creating a flow on a file in M...
Power Automate Creating Azure DevOps Items
Enhanced ‘Selected Row’ Trigger Now Available in Power Automate
We’re excited to witness the return of an enhanced ‘When a record is selected’ trigger in Power Automate, that was previousl...
Power Automate – View a Power Automate visual in a Power BI report announcement
The Power Automate team has announced the general availability of a new feature that allows users to embed and run a flow from a Power BI repo...
Dynamics 365 Business Central: How to create Sales Order from Purchase Order with Power Automate – Copy Document from PO to SO
Hi, Readers.Today I would like to talk about how to create Sales Order from Purchase Order with Power Automate (Copy Document from PO to ...
Power Automate – Use undo and redo while you build cloud flows in the designer announcement
The announcement of the "Use undo and redo while you build cloud flows in the designer" feature in Power Automate has been made. This feature ...
Power Automate – Select instead of type email addresses in Outlook and Teams announcement
The Power Automate team has announced a new feature for Outlook and Teams that enhances the email suggestion feature. The 'Select instead of t...
Power Automate – View two action properties panes simultaneously announcement
Power Automate users, get ready for an exciting new update! The "view two action properties panes simultaneously" feature has been announced, ...
July 2024 update of Power Automate for desktop
Power Automate for desktop comes with new great additions in 2024 July’s release, including a new Excel automation action, environment routing...
Streamline Multilingual Customer Support using Language Detection Prebuilt Model in Power Automate
The language detection prebuilt model figures out the main language of a text document. It looks at the text and gives back the detected langu...