Deluge Scripting in Change Triggers 

Trigger rules specify conditions under which predefined actions must be performed on incoming change requests. These are useful for calling actions after the change requests are created, especially for performing actions in other modules or in third-party applications. 

You can build trigger actions with custom functions. 

Before you write custom functions for change triggers, we recommend that you learn how to configure and use change triggers in ServiceDesk Plus Cloud.

 

Custom Functions for Change Trigger Actions 

To write a custom function that can be used as change trigger action, follow the steps given below:

As demonstrated in the following screenshot, 'changeObj' is passed as the input argument for the custom functions used in change triggers. 
 

 

'changeObj' contains the details of the change request on which the trigger must act. The custom function returns a 'void' value.
 

Let's consider a sample script to add a pre-configured rollout plan to a change request. As a prerequisite, you must configure an additional field with the rollout plan in a change template. When a change request is created using the template, the rollout plan supplied in the additional field will be automatically updated to the Rollout Plan field in the change request.
 

/*Provide the additional field key. For example, 'udf_char1'*/
rollOutPlanUdfField = "<additional field key>";
/*Gets the portal name from the 'context' object*/
portalName = context.get("instance");
/*Gets the ID of the change request*/
changeId = changeObj.get("id");
/*Checks if the additional field contains any value*/
if(changeObj.get("udf_fields") != null && changeObj.get("udf_fields").contains(rollOutPlanUdfField) && changeObj.get("udf_fields").get(rollOutPlanUdfField) != null && changeObj.get("udf_fields").get(rollOutPlanUdfField).trim() != "")
{
    /*Gets the value of the additional field*/
    rollOutPlan = changeObj.get("udf_fields").get(rollOutPlanUdfField).trim();
    /*Constructs criteria to update 'Rollout Plan' of the change request*/
    rollOutPlanParameter = {"input_data":{"change":{"roll_out_plan":{"roll_out_plan_description":rollOutPlan}}}};
    /*Makes an API call to update 'Rollout Plan' of the change request*/
    changePutResponse = zoho.sdp.invokeurl
    [
        url :"/app/" + portalName + "/api/v3/changes/" + changeId
        type :PUT
        parameters:rollOutPlanParameter
    ];
}

 

 

Test Execution of Scripts 

After writing the custom function, you can test run it by following the steps given below: 

If you make any API calls by using zoho.sdp.invokeurl or invokeurl while testing the custom function, the API will be invoked. Make sure you don't invoke an API that might result in unintended consequences. 

 

 

Debugging Tip 

When you test a custom function, you can debug the code and print the output by using a statement called info. For example, to understand the structure of 'changeObj' and 'context', you can simply run the following script and study the response.
 

info changeObj;
info context;  
 

 

For a quick summary of how to use custom functions across different features in ServiceDesk Plus Cloud, visit this link