Business rules automate various tasks, such as delivering incident and service requests to technician support groups; assigning a technician, status, or priority to a request; or even sending email notifications.
Business rules are site-based, run on all incoming requests, and can be applied to requests when they are created, edited, or deleted. If an incoming request fulfills certain pre-specified conditions, business rules ensure that certain actions are performed automatically.
Business rules consist of two main parts namely Conditions and Actions and you can use custom functions to configure both conditions and actions.
Before you write custom functions for business rules, we recommend that you learn how to configure and use business rules in ServiceDesk Plus Cloud.
To write a custom function that can be used as business rule condition, follow the steps given below:
Go to Setup > Developer Space > Custom Functions > Request - Business Rule (or) Abort Timer Conditions. (You can alternately write the custom function while creating/editing a business rule.)
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' and 'context' will be passed as arguments for the custom function:

'requestObj' will store the details of the request on which the business rule must act. 'context' will store the current instance and the logged-in user details.
If the custom function in the business rule is configured to execute upon request edit, then the context object will additionally contain 'initialObj' and 'modifiedFields'. 'initialObj' will store the original request values and 'modifiedFields' will store the fields whose values are modified.
You must write the custom function such that it returns a boolean value. Actions that you configure in the business rule will be executed if the custom function returns 'true'.
Let's consider a sample script that returns 'true' if the request subject contains 'New issue':
Let's consider a scenario in which you must prevent request duplication by users and also restrict them to create only 3 requests of the same category in a span of 24 hours. You can automate this check by using the following script in a business rule condition.
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.
Deluge allows debugging through an action called info. You can use this action to print the output of your custom function.
For example, to understand the structure of requestObj and context, you can simply run the following script and study the response.
To write a custom function that can be used as business rule action, follow the steps given below:
Go to Setup > Developer Space > Custom Functions > Requests - Business Rule Actions. (You can alternately write the custom function while creating/editing a business rule.)
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' and 'context' will be passed as arguments for the custom function:

You must write the custom function such that it returns 'requestObj'. Also, the returned value will be of the Map data type.
Changes that are made to 'requestObj' values will be updated in the request on which the business rule acts.
The new field values must be returned from the custom function in a specific format as demonstrated below:
Let's consider a sample script to update request subject to 'Firewall Upgrade' and Priority to 'High'.
Let's say you want to assign high priority to requests from Network/Internet category. You can automate this action by using the following script in a business rule action:
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.