Monday 24 September 2018

Create Custom Workflow in AX 2012

Today, I will be discussing about how to develop a custom workflow in AX 2012. Let's say we have a scenario in which we need to create a custom form for making any request and it requires approval from different authorities. Following are the steps for create custom workflow.

Step 1) Create a new enum type. Enum type will be used for defining the state or status of the workflow. For this right on base enum group in your project and select Base Enum option.

Step 2) Add following elements in the enum.














Step 3) Add this enum in your custom table and override the canSubmitToWorkflow() on table. This method will be used for defining workflow submission criteria or condition on which workflow will be enabled.








Step 4) Add another method for updating the status of the workflow.














Step 5) Now create a custom query.  Workflow will be using this query to define the tables and fields in order to define the data set available. For this right click on queries group in your project and create a new query.  Add your custom table as data source in query and set dynamic field value to yes in order to show all fields.













Step 6) Create a new workflow category. It will determine the module in which workflow will be enabled. For this right click on workflow category group in your project and create a new category. Set its label and select the module in which you want your workflow to be enabled. In my case I have selected Human resource module.










Step 7) Create a new workflow type using the wizard. For this go to AOT-> Workflows -> Workflow types -> Right click on it -> Addins -> Workflow type wizard.  You need to set out here workflow category, document menu item  and query.

Category      - Name of workflow category
Query           - Name of the query
Document    - Name of the display menu item for document form

On its generation following artifacts will be created.
1. Workflow type
2. Classes
      - Document class it will extend workflow document
      - Event handler class it will used for implementation of workflow events
      - Submit Manager class
3. Action menu item
     - Submit menu item - Points to submit manager class
     - Cancel menu item - Points to workflow cancel manager class


















Step 8) Enable workflow on your custom detail form and custom list page. For this you need to set below mentioned properties on design of form.





Step 9) Add logic in Submit Manager class. I have create a separate method with submitLeaveRequest naming and calling it from main method of submit manager class.


















Step 10) Create a new workflow approval element using wizard. For this go to AOT -> Workflow -> Approvals -> Add-ins ->  Approval wizard
Add following information on it and it will create list of artifacts
- Name of workflow approval
- Workflow document
- Document menu item
    -  Document field group

Step 11) Now add code in workflow event handler class and workflow approval event handler class.
Workflow event handler class code

















Workflow approval event handler class













Step 12) Now add code in newly created Resubmit Manager class.













Step 13) Add workflow approval item in workflow type. For this expand your workflow type and add approval element in supported elements node.








Step 14) Now its time for designing the workflow. I am creating a workflow in human resource module. So for this Go to Human resource -> Setup -> Human resource workflows
Click on new workflow button and select your custom workflow type then click on create  workflow button
Note: Before designing new workflow. Execute incremental CIL.




















Step 14) Define start and end states of workflow.
For this you need to go through below mentioned steps
- Drag your approval elements from Toolbox on the left of designer.
- Connect the bottom of start state with top of approval element.
- Connect the bottom of approval elements with top of the end state.
- Resolve issue : For instance you may require to add step. For this double click on approval element. It will navigate you to step screen. Now right click on step and open its properties add assignments, workflow item subject and work flow item instructions if required.
- Activate your workflow


















Step 15) Go to your list page form and you will see your workflow bar there.





No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Connect and upload in azure blob with azure key vault using x++

 Today, I will be sharing details about file upload in azure blob using azure vault that includes pre requisite and code snippet used to it....