Tuesday, January 2, 2024

How To Create A WorkFlow In D365F&O

 

How To Create Work Flow In D-365 F&O ?


What is workflow?

A workflow in the dynamics 365 apps is a way that automate business processes without a user interaction. People usually use workflow processes to commence automation that doesn’t require any user involvement.


1.Create a Work Flow Project : ::WRE_EmployeeWorkFlowStatus;

2.Create a Base Enum:WRE_WorkFlowStatus


Next Add The Elements In BaseEnum-Below Attachment

3.Create a New Table -Regular Table -WRE+EmployeeLeaveTable;

4.Create a Fields in Table Like Below Image



5.Create Field Group In Table 


6.Create A Method override Can SubmitToWorkFlow method of This Table

   public boolean canSubmitToWorkflow(str _workflowType = '')

   {

       boolean ret;

   

       ret = super(_workflowType);

       if(this.WRE_WorkFlowStatus != WRE_WorkFlowStatus::Approved)

       {

           ret = true;

       }

       else

       {

           ret =false;

       }

   

       return ret;

   }

7.Create A New Method  Update  WorkFlowStatus 

public static void   WRE_EmployeeLeave(RefRecId recId ,WRE_WorkFlowStatus  status)
 
   {
 
       WRE_EmployeeLeave  wRE_EmployeeLeave;
 
       ttsbegin;
 
       select forupdate wRE_EmployeeLeave
           where wRE_EmployeeLeave.RecId == recId;
 
     wRE_EmployeeLeave.WRE_WorkFlowStatus = status;
    
    wRE_EmployeeLeave.update();
 
       ttscommit;

  }


8.Create a WorkFlow Custom Form  New Form WRE_EmployeeLeaveForm 

Set allowEdit Property of enum control in the Grid to No.

9.Create a Display Menu Iteam In Form 

10.Enter the create form name in the object property  and set the label of the menu item,


11.Now Create an extension of Account Receivable Module in The Project 

12.Create a New Query  and Insert The Table In data set the dyanmic field property  to set Yes



13.B
uild the project with database synchronization.

14.Add work flow category “CustomWorkflowCategory


Create A Module In Data Workflow Category Property label  

Create Add the Work Flow Type 

A new window will appear. Enter category name, query name, display menu item name.




Below classes and action menu items will automatically be created.

No alt text provided for this image


Change the label of workflow type submit action menu item.

No alt text provided for this image

Change the label of workflow type cancel action menu item

No alt text provided for this image

Add the below code in submit manager class.

public class EmployeeLeaveWorkflowTypeSubmitManager 
{
   public static void main(Args args)
   {
       //  TODO:  Write code to execute once a work item is submitted.
       recId   recId;// = _args.record().RecId;
       WorkflowCorrelationId   workflowCorrelationId;
       WorkflowTypeName        workflowTypeName =workflowtypestr(EmployeeLeaveWorkflowType);
       WorkflowComment         note ="";
       WorkflowSubmitDialog    workflowSubmitDialog;
       WRE_EmployeeLeave       employeeLeave;
       // InventTransferTable     inventTransferTable;
 
       workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
       workflowSubmitDialog.run();
       if (workflowSubmitDialog.parmIsClosedOK())
       {
           recId               = args.record().RecId;
           employeeLeave = args.record();
           note = workflowSubmitDialog.parmWorkflowComment();
           try
           {
               workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
               ttsbegin;
               employeeLeave.selectForUpdate(true);
               employeeLeave.WRE_WorkFlowStatus = WRE_WorkFlowStatus::Submit;
               employeeLeave.update();
               ttscommit;
 
               info("Submitted to workflow.");
           }
           catch(exception::Error)
           {
               info("Error on workflow activation.");
           }
       }
 
   }
 
}
Add the below code in workflow type event handler class

 

/// <summary>

/// The EmployeeLeaveWorkflowTypeEventHandler workflow event handler.

/// </summary>

public class  EmployeeLeaveWorkflowTypeEventHandler implements WorkflowCanceledEventHandler,  

       WorkflowCompletedEventHandler,

       WorkflowStartedEventHandler

{

   public  void started(WorkflowEventArgs _workflowEventArgs)

{

       WRE_EmployeeLeave::WRE_EmployeeLeave(_workflowEventArgs.parmWorkflowContext().parmRecId(),WRE_WorkFlowStatus::None);

       // TODO:  Write code to execute once the workflow is started.

}

 

   public void canceled(WorkflowEventArgs _workflowEventArgs)

{

       WRE_EmployeeLeave::WRE_EmployeeLeave(_workflowEventArgs.parmWorkflowContext().parmRecId(),WRE_WorkFlowStatus::Cancelled);

// TODO:  Write code to execute once the workflow is canceled.

}

 

   public void completed(WorkflowEventArgs _workflowEventArgs)

{

       WRE_EmployeeLeave::WRE_EmployeeLeave(_workflowEventArgs.parmWorkflowContext().parmRecId(),WRE_WorkFlowStatus::Approved);

// TODO:  Write code to execute once the workflow is completed.

}

 

}





Change the Workflow Enable property to Yes and add workflow type name on the form design property.


Build the project with database synchronization.

Now add the workflow approval “CustomWorkflowApproval



A window will appear.

  1. Select workflow document (It’s the class which was created automatically it returns the query).
  2. Enter field group of the custom table.
  3. Enter display menu item name.




Some classes and action menus created automatically.


Add the below code in workflow approval event handler class.

/// <summary>
/// The EmployeeLeaveWorkflowApprovalEventHandler workflow outcome event handler.
/// </summary>
public final class EmployeeLeaveWorkflowApprovalEventHandler implements WorkflowElementCanceledEventHandler,
       WorkflowElemChangeRequestedEventHandler,
       WorkflowElementCompletedEventHandler,
       WorkflowElementReturnedEventHandler,
       WorkflowElementStartedEventHandler,
       WorkflowElementDeniedEventHandler,
       WorkflowWorkItemsCreatedEventHandler
{
   public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO:  Write code to execute once the workflow is started.
}
 
   public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
       WRE_EmployeeLeave::WRE_EmployeeLeave(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), WRE_WorkFlowStatus::Cancelled);
 
// TODO:  Write code to execute once the workflow is canceled.
}
 
   public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
       WRE_EmployeeLeave::WRE_EmployeeLeave(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), WRE_WorkFlowStatus::Approved);
 
// TODO:  Write code to execute once the workflow is completed.
}
 
   public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
      // WRE_EmployeeLeave::updateWorkflowStatus(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), WRE_WorkFlowStatus::Cancelled);
 
// TODO:  Write code to execute once the workflow is denied.
}
 
   public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO:  Write code to execute once change is requested for the workflow.
}
 
   public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO:  Write code to execute once the workflow is returned.
}
 
   public void created(WorkflowWorkItemsEventArgs _workflowWorkItemsEventArgs)
{
       //WRE_EmployeeLeave::WRE_EmployeeLeave(_workflowWorkItemsEventArgs.parmWorkflowContext().parmRecId(), WRE_WorkFlowStatus::Submit);
 
// TODO:  Write code to execute once work items are created.
}
 
}

Change the label of workflow approval Approve Action Menu Item.
change the label of workflow approval Approve Action Menu Item .
change be like Rejected and Submit Action Menu item.


Now open workflow type and right click on supported elements section and select “New Workflow Element Reference

Enter workflow approval name in the Element Name property and also provide a name.


Change the label of workflow type.

Now build the project with database synchronization.

Open the form in d365 browser, see there is no workflow button enable. So, we need to configure the custom workflow in the attached module like we setup it in the Accounts Receivable module.

No alt text provided for this image

Go to Accounts Receivable module > Setup > Accounts receivable workflows. Click on the Accounts receivable workflows

No alt text provided for this image

Click on New button.

No alt text provided for this image

Select custom workflow type from the list (It’s the label of workflow type)

No alt text provided for this image

A new window will appear click on “Run” button.

No alt text provided for this image

A new form will open, enter email and password

No alt text provided for this image

If you are not logged in with admin account the below error will appear.

No alt text provided for this image

If you are logged in with admin account the below window will appear; Design the workflow according to your need.

No alt text provided for this image

Click on “Basic settings” and add placeholder.

No alt text provided for this image
No alt text provided for this image

Navigate to assignments and add select “User” option.

No alt text provided for this image

Click on “User” button and add user there.

No alt text provided for this image

Now click on “Basic Settings” Button under assignment window and provide placeholders.

No alt text provided for this image

Now drag workflow approval in the workflow window

No alt text provided for this image

Click on start and drag the connector (Arrow) to the workflow approval function.

Scroll the bar you will find end function.

Click on workflow approval and drag the connector (Arrow) to the end function.

No alt text provided for this image

Click “Save and close” button.

No alt text provided for this image

Click “OK” button and another form will open, click on “Activate” button there to activate the workflow.

Go back and now open the form again and you will see the workflow button visible there.

No alt text provided for this image






No comments:

Post a Comment

How To Create A WorkFlow In D365F&O

  How To Create Work Flow In D-365 F&O ? What is workflow? A workflow in the dynamics 365 apps is a way that automate business processes...