Sample Scenario for Custom Trigger in Change module

     

    With Custom Trigger, you can automatically trigger the required 'Action' using the script file or custom class file. This document will give a clear idea on triggering class/script file for a sample situation.

    1.In the 'New Action' window, provide the name and description for the new action. From the drop-down list, select the instant at which the action has to be executed.
    2.Set the 'Criteria' fields, its corresponding conditions and their field values.
    3.Select the 'Action Type' and the corresponding script/class file that has to be triggered. Deselecting 'Stop processing subsequent actions' checkbox will execute successive action even after an action rule is applied on a change.

     


     

     

    Now that we know how to create a new action , let us walk through a sample scenario where 'custom triggers' can be put to good use.
    Scenario: Website is down for payroll advice view and the new server needs to be quickly installed.

    For the above emergency situation where the impact is 'High', the required 'Action' can be triggered through the script/class file.

    The members of the E-CAB can be configured well in advance for such emergency situations and the corresponding class/script file can be executed. To perform actions, it is necessary to have the Class file in the specified location for the action implementation.

    In case of 'class' file:
    *By default, jar should be placed in [SDPMSP_Home]/integration/lib/ directory
    *Example:com.servicedeskplusmsp.integration.ChangeActionImplementation
    Note: It is necessary that the class file has to converted to jar file to implement the action.





    Let us consider the situation where the roles performed by the E-CAB members have to be updated. The following JSON format has to be followed inorder to trigger the required action.

    UPDATE_ROLES (Script/Class)

    {

        "message": "Adding Emergency CAB members through Custom Trigger",

        "operations": [

            {

                "operation_name": "UPDATE_ROLES",

                "input_data": {

                    "change": {

                        "roles": [

                            {

                                "id": 5,

                                "name": "Line Manager",

                                "users": [

                                    {

                                        "email": "Aaron@xyz.com",

                                        "name": "Aaron"

                                    },

                                    {

                                        "email": "Abby@xyz.com",

                                        "name": "Shawn Adams"

                                    }

                                ]

                            }

                        ]

                    }

                }

            }

        ]

    }


     

    Following is a sample implementation for 'Change' Action :

    package com.servicedeskplus.integration;

    import com.manageengine.servicedesk.actionplugin.executor.ActionInterface

    import com.manageengine.servicedesk.actionplugin.executor.ExecutorData

        /** 

         *Trigger implementation has to be done in this class

         *@executorData, contains DataJSON,diffJSON

         */

    public class ChangeActionImplementation extends DefaultActionInterface {

     

        public JSONObject execute(ExecutorData executorData) throws Exception {

                //get the change data in api format 

                JSONObject changeData = executorData.getDataJSON();

                //fetch the field impact

                JSONObject impact = changeData.get("impact");

                //get the value associated with impact 

                String impactName = impact.get("name");

     

                JSONObject returnJSON = new JSONObject();

     

                //Array of operations to be performed in trigger ,currently UPDATE_ROLES option is alone provided in change 

                JSONArray operations = new JSONArray();

     

                //JSON for specific operation 

                JSONObject operation = new JSONObject();

     

                //JSON for providing operation details 

                JSONObject input_data = new JSONObject();

     

                //JSON for entity change 

                JSONObject change = new JSONObject();

     

                //Array of roles to be configured 

                JSONArray roles = new JSONArray();

     

                //JSONObject for Role details 

                JSONObject roleObject = new JSONObject();

     

                //array of users to be configured 

                JSAONArray users = new JSONArray();

     

                //JSONObject for user details 

                JSONObject user1 = new JSONObject();

                JSONObject user2 = new JSONObject();

     

                if (impactName.equalsIgnoreCase("High") {

                        returnJSON.put("message", "Adding Emergency CAB members through Trigger");

                        operation.put("operation_name", "UPDATE_ROLES");

                        roleObject.put('id': ROLEID of CAB);

                        roleObject.put("name": "Role Name ,Here CAB");

                        user1.put("email": "emailId of user");

                        user1.put("name": "name of user");

                        user2.put("id": ID of user);

     

                        // Enter the name of the user.

                        user2.put("name": "name of user");

                        users.put(user1);

                        users.put(user2);

                        roleObject.put("users", users);

                        roles.put(roleObject);

                        change.put("roles", roles);

                        input_data.put("change", change);

                        operation.put("input_data", input_data);

                        operations.put(operation);

                        returnJSON.put("operations", operation);

                    } else {

                        returnJSON.put("message", "Adding CAB members through Trigger");

                        operation.put("operation_name", "UPDATE_ROLES");

                        roleObject.put("id ": ROLEID of CAB);

                        roleObject.put("name": "Role Name, Here CAB ");

                        user1.put("email": "emailId of user");

                        user1.put("name": "name of user");

                        user2.put("id": ID of user);

                        user2.put("name": "name of user");

                        users.put(user1);

                        users.put(user2);

                        roleObject.put("users", users);

                        roles.put(roleObject);

                        change.put("roles", roles);

                        input_data.put("change", change);

                        operation.put("input_data", input_data);

                        operations.put(operation);

                        returnJSON.put("operations", operation);

                    }

                    return returnJSON;

                }

    Following are the methods used in Class implementation:

    *getDataJSON()- To get the input in API format which provides complete information about the 'change'.
    *getDiffJSON()- Returns the details iof the fields that are modified recently in the change To get information about the recently modified fields in the 'change'.

    Click here to view the values returned in getDataJSON() and getDiffJSON() 

    Having known the JSON format , the action can be executed either via class file or script file. To perform actions, it is necessary to have the Script file in the specified location for the action implementation.

    In case of 'script' file:
    *By default, scripts should be placed in [SDPMSP_Home]/integration/custom_scripts/ directory
    *Example: py addApprovers.py

     



    Click here to view a sample script file for 'Change' Action:

    Zoho Corp. All rights reserved.