Business Rules

Business Rules

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: Conditions and Actions. You can use custom functions to configure both conditions and actions.
Supported Modules
Role Required
Requests
SDAdmin, SDSiteAdmin, HelpDeskConfig
Changes
SDAdmin
 

Configure Custom Functions for Business Rules

  1. Go to Setup > Developer Space > Custom Functions.
  2. In the module drop-down, select the relevant operation:
    1. To configure business rule condition - select Business Rule (or) Abort Timer Conditions (or) Workflow Actions
    2. To configure business rule action - select Business Rule Actions
  3. Click New Custom Function. You can alternately write the custom function while creating/editing a business rule.
  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.
  1. For requests, 'requestObj' and 'context' will be passed as arguments in the custom function.
  2. For changes, 'changeObj' and 'context' will be passed as arguments in the custom function. 

Note:
'requestObj' or 'changeObj' stores the details of the request/change on which the business rule must act.  

'context' stores the current instance and the logged-in user details.  

If the custom function is configured for a request/change 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:
Business Rules Condition: Ensure custom function returns "Boolean" value. Actions that you configure in the business rule will be executed if the custom function returns 'true'.

Info
 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.  

Business Rules Action: Ensure custom function returns "Map" value.

Info
Changes that are made to 'requestObj' values will be updated in the request on which the business rule acts.  
You can update only the following request fields in requestObj: subject, resolution, mode, group, item, level, impact, service_category, update_reason, priority, udf_fields, impact_details, subcategory, status, request_type, description, urgency, technician, category. 

Test Execution of Scripts

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

  1. info requestObj;
  2. info context;
  3. return true;
 

Sample Scripts

Business Rule Condition:
Let's consider a sample script that returns 'true' if the request subject contains 'New issue':

  1. subject = requestObj.get("subject");
  2. if(subject.contains("New issue")){
  3.     return true;
  4. }
 
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.

  1. if(requestObj.containsKey("category"))
  2. {
  3.     category_name = requestObj.get("category").get("name");
  4.     request_creation_time = requestObj.get("created_time").get("value");
  5.     request_creation_time = request_creation_time.toDate().toLong();
  6.     check_upto_time = request_creation_time - 24 * 60 * 60 * 1000;
  7.     requester_email = requestObj.get("requester").get("email_id");
  8.     criteria = "{list_info:{search_criteria:{field:category.name,values:['" + category_name + "'],condition:like,children:[{field:created_time.value,condition:GT,logical_operator:and,value:'" + check_upto_time + "'},{field:requester.email_id,condition:like,logical_operator:and,values:['" + requester_email + "']}]}}}";
  9.     response = zoho.sdp.invokeurl
  10.     [
  11.         url :"/app/itdesk/api/v3/requests"
  12.         type :GET
  13.         parameters:{"input_data":criteria}
  14.     ];
  15.     requests = response.get("requests");
  16.     if(requests.toJSONList().size() > 2)
  17.     {
  18.         return true;
  19.     }
  20. }
  21. return false;
 
Business Rule Action:
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'.
  1. requestObj.put("subject", "Firewall Upgrade");
  2. requestObj.put("priority", {"name": "High"});
  3. return requestObj;
 
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:
  1. if(requestObj.containsKey("category"))
  2. {
  3.     if(requestObj.get("category").get("name") == "Internet" || requestObj.get("category").get("name") == "Network")
  4.     {
  5.         requestObj.put("priority",{"name":"High"});
  6.     }
  7. }
  8. return requestObj;
 
For a quick summary of how to use custom functions across different features in ServiceDesk Plus MSP Cloud, visit this link
    • Related Articles

    • Business Rules

      Configure Business Rules Business rules are used to automate actions on a request that fulfill certain incoming criteria. The criteria for the rules are set using the request fields. Business rules can be used to automate actions on incident, ...
    • Form Rules

      Form Rules allow you to define rules to automate certain actions on form fields based on custom conditions. Supported Form Types: Incident request forms, service request forms, change forms, problem forms, and release forms. Form Rules are executed ...
    • Closure Rules

      Closure rules automate the collection of vital details and execute relevant actions before a record can be closed in the service desk. Supported Modules: Requests, Problems, Changes, Releases, Purchase Orders, Tasks Role Required: SDAdmin Benefits: ...
    • Sync Rules

      Sync rules define the data to be synced from assets, users, or software installations to CMDB. The synced data is populated as CIs in CMDB and linked to the corresponding asset, user, or software. You can perform various actions on CIs and their ...
    • Notification Rules

      Notification rules allow you to specify conditions when a key event must be alerted to users. Supported Modules: Requests, Problems, Changes, Projects, Release, Solutions, Assets, Purchase, Contracts, Tasks, and other general events. Role Required: ...