Trigger rules 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. You can use trigger actions for Requests, Problems, Changes, Projects, Releases, Assets, CMDB.
Request Life Cycle in ServiceDesk Plus Cloud allows admins to formulate a request resolution process with built-in guidance for the help desk technician. A life cycle ensures efficient process adherence; you can establish a directional flow, minimize the scope for human errors, and provide privileged (role-based) access to status transitions. You can also configure life cycle for Problems and Assets.
To automate processes through request life cycle, you define actions that will be executed under pre-specified conditions. Custom function execution is one of the many different types of actions in request life cycle.
Before you write custom functions for request triggers/life cycles, we recommend that you learn how to configure and use each of them.
Learn about Request Life Cycle
Request triggers and life cycle actions use the same type of custom function with the input arguments and the return type alike.
To write a custom function that can be used as a request trigger or life cycle action, follow the steps given below:
Go to Setup > Developer Space > Custom Functions > Requests - Trigger (or) Life Cycle Actions. (You can alternately write the custom function while creating or editing a request trigger/life cycle.)
Click New custom function.
Provide a name and description for your custom function.
Write the custom function on the Deluge Script Editor by using the following pointers and then save the function:
As demonstrated in the following screenshot, 'requestObj' will be passed as argument for the custom function:

The custom function returns a '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.
Let's consider a sample script to create a new change with the subject of a request:
Let's consider a scenario in which you must 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.
Let's consider another scenario in which you must 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.
After writing the custom function, you can test it by following the steps given below:
Click Save & Execute Script.
Choose a sample request from the list of requests displayed and click Next.
The data that will be passed to the custom function will be displayed under the parameter 'requestObj'. Optionally, you can modify the 'requestObj' values. Click Execute.
The script will be executed, and the output will be displayed.
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.