This guide will explain every step needed to create your custom workflow in Dynamics 365 Create Enum The base enumeration is used to define the status of the workflow. Here are the steps needed to define it:
– Create a new Enum for the workflow status
Create A New Field on the Table – Here, we use the table SMAAgreementTable as an example. Create an extension of the table and drag Enum to table.
Create Methods on the Table Next, you will be required to create methods on the table using the following steps:
Create a new class and name it “devSMAAgreementTable_Extension” Extend the table “SMAAgreementTable”. Create methods with the following names The “canSubmitToWorkflow” method will use a chain of command for the next keyword.
public boolean canSubmitToWorkflow ( str _workflowType )
{
boolean ret = next canSubmitToWorkflow ( _workflowType ) ;
ret = this . RecId != 0 & amp ; & amp ; this . workflowStatus == workflowstatus :: Draft ;
return ret ;
}
Create a New Query Creating a new query is easy:
Here we use the SMAAgreementTableListPage query Create Workflow Category Click on Add > New Item > Business Process and Workflow > Workflow Category Enter a proper name Set the properties as given belowLabel = “Service agreement workflow category” Module = Salesorder (as of now we will add workflow to AR. So, the workflow will list under the AR module) Create Workflow Type Create a new workflow type with the following steps:Click on Add > New Item > Business Process and Workflow > Workflow Type – Edit the devServiceAgreementWFTypeEventHandler class as given below
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 ) ;
}
– Write the following code on the submit manager class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 – To create a workflow approval, simply click on Add > New item > Business process and workflow > Workflow Approval
– Update the devServiceAgreementWFApprovalEventHandler eventhandler class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 an approval supported element on workflow type under devServiceAgreementWFType > Supported elements
– Enable Workflow on Form
– Create Workflow
Comments
Post a Comment