Triggers

Triggers

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


Supported Modules
Role Required
Requests
SDAdmin, SDSiteAdmin, HelpDeskConfig
Problems, Changes, Projects, Releases, Solutions, Assets, CMDB, Purchase, Contracts, and Custom Modules
SDAdmin
 

Configure Custom Functions for Triggers

  1. Go to Setup > Developer Space > Custom Functions.
  2. In the module drop-down, select Trigger (or) Life Cycle (or) Actions.
  3. Click New Custom Function. You can alternately write the custom function while creating/editing a trigger.
  4. Fill out the necessary information as described in the below:
Field
Description
Custom Function Name*
Provide a unique name for the custom function.
Description
Describe the objective and usage of the custom function.
Applies to
Choose the sub-entities within the module where the custom function is applied.
Deluge Script Editor
Compile the custom function in the Deluge Script Editor using a simple drag-and-drop motion. To learn more about Deluge and how to write custom functions, click here.

Depending on the module selected, the following arguments will be passed in the custom function.
Requests - 'requestObj' and 'context'
Problems - 'problemObj' and 'context'
Changes - ' changeObj ' and 'context'
Projects - 'projectObj' and 'context'
Releases - 'releaseObj' and 'context'
Solutions - 'solutionObj' and 'context'
Assets - 'assetObj' and 'context'
CMDB - 'ciObj' and 'context'
Purchase - 'purchaseorderObj' and 'context'
Contracts - 'contractObj' and 'context'
Custom Module - 'cm[custommodulename]Obj' and 'context'
'[module]Obj' - Stores the details of the request on which the trigger must act.
'context' - Stores the current instance and the logged-in user details. 

Info
If the custom function is configured for a module sub-entity, the respective sub-entity object will be passed in the parameter. 
*mandatory fields
  1. After compiling the custom function, click Save or Save & Execute Script.

Points to remember:

Ensure custom function returns "void" value.

You cannot return any object from the custom function to modify the request. You can, however, modify the request by making API calls. 

Test Execution of Scripts

After writing the custom function, you can test it by following the steps given below:
  1. Click Save & Execute Script.
  2. Choose a sample record from the list of records displayed and click Next.
  3. The data that will be passed to the custom function will be displayed under the parameter '[module]Obj'. Optionally, you can modify the '[moduleObj' values.
  4. Click Execute.
Info
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 requestObj and context, you can simply run the following script and study the response.
  1. info requestObj;
  2. info context;   
 

Sample Scripts

Scenario: Create a new change with the subject of a request:
  1. myInstance = context.get("instance");
  2. subjectOfRequest = requestObj.get("subject");
  3. resp = zoho.sdp.invokeurl[
  4.     url: "/app/itdesk/api/v3/changes"
  5.     type: POST
  6.     parameters: {"input_data": {"change":{"title":subjectOfRequest}}}
  7. ];
 
Scenario: Automate the creation of GoToMeeting events for specific requests. You can perform this action by using the following script in a Request Trigger. Before using this script, create a new service request called 'GoToMeeting Booking' with start and end times added as additional fields in the service request template, and change the same in the script.
  1. gotomeeting_token = "<your goto meeting token>";
  2. portal_name = "<your portal>";
  3. start_time_udf_key = "<your adiitional date field key - to note start time>";
  4. end_time_udf_key = "<your adiitional date field key - to note end time>";
  5. /*Code logic from the below*/
  6. template = requestObj.get("template").get("name");
  7. if(template == "GoToMeeting Booking")
  8. {
  9.     subject = requestObj.get("subject");
  10.     request_id = requestObj.get("id");
  11.     start_time = requestObj.get("udf_fields").get(start_time_udf_key).get("value");
  12.     end_time = requestObj.get("udf_fields").get(end_time_udf_key).get("value");
  13.     meeting_start_time = start_time.toTime().toString("yyyy-MM-dd'T'HH:mm:ss'.000Z'");
  14.     meeting_end_time = end_time.toTime().toString("yyyy-MM-dd'T'HH:mm:ss'.000Z'");
  15.     gotomeeting_data = Map();
  16.     gotomeeting_data.put("subject",subject);
  17.     gotomeeting_data.put("starttime",meeting_start_time);
  18.     gotomeeting_data.put("endtime",meeting_end_time);
  19.     gotomeeting_data.put("passwordrequired","false");
  20.     gotomeeting_data.put("conferencecallinfo","--from sdpod--");
  21.     gotomeeting_data.put("timezonekey","string");
  22.     gotomeeting_data.put("meetingtype","immediate");
  23.     header = {"Authorization":gotomeeting_token,"Accept":"application/json","Content-Type":"application/json"};
  24.     /*Below line triggers api call to gotomeeting and response provided by gotomeeting is captured in response_from_goto*/
  25.     response_from_goto = postUrl("https://api.getgo.com/G2M/rest/meetings",gotomeeting_data + "",header + "",true);
  26.     join_url = response_from_goto.toMap().get("joinURL");
  27.     /*Below code creates notes in sdpod with the joinurl, which was got from gotomeeting's response*/
  28.     sdpod_response = zoho.sdp.invokeurl
  29.     [
  30.         url :"/app/" + portal_name + "/api/v3/requests/" + request_id + "/notes"
  31.         type :POST
  32.         parameters:{"input_data":{"request_note":{"description":"A meeting has been scheduled in gotomeeting by the system. Join Url for gotomeeting is <a href='" + join_url + "'>" + join_url + "</a>"}}}
  33.     ];
  34. }
 
Scenario: Automate the creation of change requests for service/incident requests. You can do so by defining a request trigger. The following script creates a change for a request by copying the request subject to the change title and associates the change with the request.
  1. /*Provide your portal name*/
  2. portal_name = "<your portal>";
  3. /*Triggers an API call to create a change with a title copied from the corresponding request's subject.*/
  4. new_change_response = zoho.sdp.invokeurl
  5. [
  6.     url :"/app/" + portal_name + "/api/v3/changes"
  7.     type :POST
  8.     parameters:{"input_data":{"change":{"title":requestObj.get("subject")}}}
  9. ];
  10. /*Triggers an API call to associate the change with the corresponding request */
  11. associate_request = zoho.sdp.invokeurl
  12. [
  13.     url :"/app/" + portal_name + "/api/v3/changes/" + new_change_response.get("change").get("id") + "/initiated_by_requests"
  14.     type :POST
  15.     parameters:{"input_data":{"change_initiated_by_request":{{"request":{"id":requestObj.get("id")}}}}}
  16. ];
 
Scenario: 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.
  1. /*Provide the additional field key. For example, 'udf_char1'*/
  2. rollOutPlanUdfField = "<additional field key>";
  3. /*Gets the portal name from the 'context' object*/
  4. portalName = context.get("instance");
  5. /*Gets the ID of the change request*/
  6. changeId = changeObj.get("id");
  7. /*Checks if the additional field contains any value*/
  8. 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() != "")
  9. {
  10.     /*Gets the value of the additional field*/
  11.     rollOutPlan = changeObj.get("udf_fields").get(rollOutPlanUdfField).trim();
  12.     /*Constructs criteria to update 'Rollout Plan' of the change request*/
  13.     rollOutPlanParameter = {"input_data":{"change":{"roll_out_plan":{"roll_out_plan_description":rollOutPlan}}}};
  14.     /*Makes an API call to update 'Rollout Plan' of the change request*/
  15.     changePutResponse = zoho.sdp.invokeurl
  16.     [
  17.         url :"/app/" + portalName + "/api/v3/changes/" + changeId
  18.         type :PUT
  19.         parameters:rollOutPlanParameter
  20.     ];
  21. }
 
For a quick summary of how to use custom functions across different features in ServiceDesk Plus MSP Cloud, visit this link.
    • Related Articles

    • Triggers

      Triggers execute automated actions when certain events occur in the service desk. Triggers are useful for executing condition-based actions across modules or in third-party applications. Use Case: Triggers automate several processes, such as sending ...
    • Zapier Integration

      Zapier is a no-code automation platform that connects different apps and services, allowing you to automate repetitive tasks. You can connect ServiceDesk Plus MSP Cloud with various external web applications via Zaps. A Zap is an automated workflow ...
    • Use Cases

      Scenario: Convert Incident to Service Request Currently, only incident requests can be created via email using the default template. However, Zylker wants to create service requests based on specific keywords found in the email, aligning with their ...
    • Custom Actions

      Custom actions refer to user defined actions that can be performed on different entities across modules. For a custom action to be performed on an entity, it should be used with automation rules, subject to the availability of support. The following ...
    • Overview

      ServiceDesk Plus Cloud MSP comes with built-in capabilities that allow users, who have minimal technical expertise, to set up rule-based automations. Administrators can establish a service desk that handles requests on auto-pilot via automations. The ...