Scheduled Functions

Scheduled Functions

Automate the execution of custom functions at regular intervals of time using schedules. For example, you can configure a schedule to escalate requests that have remained unapproved for a definite time to the stakeholders. You can also regularly sync data between ServiceDesk Plus MSP Cloud and any third-party applications.

Using Custom Functions in Schedules  

  1. Go to Setup > Developer Space > Custom Functions > Scheduled Functions. (You can alternately write the custom function while creating a schedule.)
  2. Click New Custom Function.
  3. Provide a name and description for your custom function.
  4. Write the custom function on the Deluge Script Editor and then save the function.
The custom function used in schedules has the input argument 'context' that contains 'instance'. The custom function must return a 'Map' object. The returned Map object is currently not processed. 

You can also return an empty map by using the following syntax:
  1. return map();  

 
Test Execution of Scripts   

After writing the custom function, you can test it by clicking Save & Execute Script. The script will be executed and a success/failure message will be displayed.
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 'context', you can simply run the following script and study the response.
  1. info context;
  2. return Map();

Sample  

Let's say your organization has a general practice of scheduling change requests in the distant future. Users involved in each of those change requests might lose track of time and fail to notice the beginning of the change request processing. Using the following script, you can send reminders to select users on specific dates prior to the change request processing.

  1. /*Provide the email address to be notified*/
  2. toEmail = "<email address>";
  3. /*Enter how many days before the change request's scheduled start must the notification be triggered*/
  4. reminder = "<number of days>";
  5. /*Provide the name of the portal in which you want to execute the custom function*/
  6. portalName = "<portal name>";
  7. /*Gets the current system time*/
  8. currentTime = zoho.currenttime.tolong();
  9. /*Determines the one-day window based on which the change requests must be fetched*/
  10. reminderValueEnd = currentTime + reminder.toNumber() * 86400000;
  11. reminderValueStart = reminderValueEnd - 86400000;
  12. /*Constructs criteria to fetch change requests*/
  13. changeParameter = {"input_data":{"list_info":{"row_count":"1","start_index":1,"search_criteria":{{"field":"scheduled_start_time.value","condition":"gte","value":reminderValueStart},{"field":"scheduled_start_time.value","condition":"lt","value":reminderValueEnd,"logical_operator":"and"}},"sort_field":"scheduled_start_time","sort_order":"asc"}}};
  14. /*Makes an API call to get the change requests that fulfill the specified criteria*/
  15. response = zoho.sdp.invokeurl
  16. [
  17.     url :"/app/" + portalName + "/api/v3/changes"
  18.     type :GET
  19.     parameters:changeParameter
  20. ];
  21. /*Gets the change requests from the response of the API called*/
  22. changes = response.get("changes");
  23. /*Checks if there is at least 1 change request in the response of the API called.*/
  24. if(!changes.isEmpty())
  25. {
  26.     /*Contructs the change request ID to send in the email*/
  27.     scheduledChangeId = changes.get(0).get("display_id").get("display_value") + "<br><br>";
  28.     /*Constructs 'Description' for the email*/
  29.     mailDescription = "The following change request will start in " + reminder + " days.<br><br>" + scheduledChangeId + "<br><br>This is an automated message. Please don't reply to this email.";
  30.     /*Constructs 'Subject' for the email*/
  31.     mailSubject = "Reminder for change request in ServiceDeskPlus Cloud";
  32.     /*Makes an API call to send the email*/
  33.     mailResponse = zoho.sdp.invokeurl
  34.     [
  35.         url :"/app/" + portalName + "/api/v3/changes/" + changes.get(0).get("id") + "/notifications"
  36.         type :POST
  37.         parameters:{"input_data":{"notification":{"to":{toEmail},"subject":mailSubject,"description":mailDescription,"type":"SEND_MAIL_ONLY"}}}
  38.     ];
  39. }
  40. return Map();
 
For a quick summary of how to use custom functions across different features in ServiceDesk Plus MSP Cloud, visit this link.
    • Related Articles

    • Custom Functions

      Overview Custom functions allow you to manipulate data within ServiceDesk Plus MSP Cloud and external applications. You can use custom functions to configure complex conditions or define multiple actions. For example, data under any module can be ...
    • Callback Functions

      Callback functions allow you to manipulate data within ServiceDesk Plus MSP Cloud whenever an event occurs in an external application. For example, you can write a callback function to notify and update the necessary information in ServiceDesk Plus ...
    • Schedules

      Schedules enable you to access any data from ServiceDesk Plus Cloud MSP and schedule periodic customized actions. Schedules are automated using a type of custom function called scheduled functions. Custom functions are programs that allow users to ...
    • Deployment

      This stage involves deploying the release to the production environment after the authorized technicians approve the release. Deployment involves the following: Ensure that the target environment is ready to admit the commissioned release. Analyze ...
    • 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. ...