Create custom workflow D365 finance & Operations
Create customized workflow on service management module for service agreement. There isn’t any workflow available for this module.
Difference between AX 2012 and D365 F&O Customizing workflow, which I came across, is the extension of methods on table as overlayering is now not allowed on D365 F&O. The rest of the process is the same.
Create Enum
Create a new field on the table.
Create methods on table
Create a new class. Name it “devSMAAgreementTable_Extension”
Extend for table “SMAAgreementTable”.
Create methods
canSubmitToWorkflow
UpdateCustWorkflowState
“canSubmitToWorkflow” method will be using a chain of command. (use of next keyword)
public boolean canSubmitToWorkflow(str _workflowType)
{
boolean ret = next canSubmitToWorkflow(_workflowType);
ret = this.RecId != 0 && this.workflowStatus == workflowstatus::Draft;
return ret;
}
Create new query
Create workflow category
Create workflow type
Create new workflow type as below:
Click on Add > New item > Business process and workflow > Workflow type
public void started(WorkflowEventArgs _workflowEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), workflowstatus::Pending);
}
public void canceled(WorkflowEventArgs _workflowEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), workflowstatus::Cancel);
}
public void completed(WorkflowEventArgs _workflowEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), workflowstatus::Completed);
}
public static void main(Args _args)
{
SMAAgreementTable ObjSMAAgreementTable;
devServiceAgreementWFTypeSubmitManager submitManger = new devServiceAgreementWFTypeSubmitManager();
recId _recId = _args.record().RecId;
WorkflowCorrelationId _workflowCorrelationId;
workflowTypeName _workflowTypeName = workFlowTypeStr("devServiceAgreementWFType");
WorkflowComment note = "";
WorkflowSubmitDialog workflowSubmitDialog;
//Opens the submit to workflow dialog.
workflowSubmitDialog = WorkflowSubmitDialog::construct(_args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
ObjSMAAgreementTable = _args.record();
// Get comments from the submit to workflow dialog.
note = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
// Activate the workflow.
_workflowCorrelationId = Workflow::activateFromWorkflowType(_workflowTypeName, ObjSMAAgreementTable.RecId, note, NoYes::No);
ObjSMAAgreementTable.workflowstatus = workflowstatus::Submitted;
ObjSMAAgreementTable.update();
ttscommit;
// Send an Infolog message.
info("Submitted to workflow.");
}
catch (Exception::Error)
{
error("Error on workflow activation.");
}
}
_args.caller().updateWorkFlowControls();
}
Create workflow Approval
Click on Add > New item > Business process and workflow > Workflow Approval
public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),workflowstatus::Submitted);
}
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),workflowstatus::Cancel);
}
public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),workflowstatus::Approved);
}
public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),workflowstatus::Rejected);
}
public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
SMAAgreementTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),workflowstatus::ChangeRequest);
}
Add workflow approval to workflow type
Create approval supported element on workflow type under devServiceAgreementWFType > Supported elements
Enable workflow on form
Create workflow