Custom functions can be executed using Custom Menu to perform a variety of user-defined actions within ServiceDesk Plus Cloud and external applications.
The following document will explain how to write custom functions for the Requests module specifically. However, you can follow the same instructions to write custom functions for Assets and Changes modules. The only change will be replacing 'requestObj' with 'assetObj' or 'changeObj' in the script, depending on your requirements.
1. Go to Setup > Developer Space > Custom Functions > Requests > Custom Menu Actions and click New custom function. (You can alternately write a custom function while creating/editing the Custom Menu.)

2. Provide a name and description for your custom function.
3. 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 a map value or an empty map (). Let's say the map value is requestObj. Changes that are made to 'requestObj' values will be updated in the request to which the Custom Menu applies.
The new field values must be returned from the custom function in a specific format as demonstrated in the following sample script that can be used to auto-close linked requests upon the closure of the reference request:
/*Gets the request status*/
status = requestObj.get("status").get("name");
returnMap = Map();
/*Checks if the request is closed*/
if(status.equals("Closed"))
{
/*Gets the name of the portal in which the request is logged*/
portal_name = context.get("instance");
request_url = "/app/" + portal_name + "/api/v3/requests/";
/*Checks if the request has been linked to other requests*/
if(requestObj.get("has_linked_requests").equals("true"))
{
/*Specifies criteria to fetch the linked requests*/
linked_request_criteria = {"field":"linked_to_request.request.id","condition":"is","value":requestObj.get("id")};
not_closed_criteria = {"field":"status.name","condition":"is not","value":"Closed","logical_operator":"and"};
/*Makes an API call to fetch the 10 oldest linked requests*/
fetch_response = zoho.sdp.invokeurl
[
url :request_url
type :GET
parameters:{"input_data":{"list_info":{"row_count":"10","sort_field":"display_id","sort_order":"asc","search_criteria":{linked_request_criteria,not_closed_criteria}}}}
];
requests = fetch_response.getJSON("requests");
request_ids = "";
/*Gets the IDs of the requests that are fetched*/
for each request in requests
{
request_id = request.get("id");
if(request_ids == "")
{
request_ids = request_id;
}
else
{
request_ids = request_ids + "," + request_id;
}
}
if(request_ids != "")
{
/*Makes an API call to close the requests that are fetched*/
close_response = zoho.sdp.invokeurl
[
url :request_url + "close"
type :PUT
parameters:{"ids":request_ids}
];
if(close_response.get("response_status").get(0).get("status") == "success")
{
returnMap.put("success",true);
returnMap.put("message","Child requests are changed successfully");
}
else
{
returnMap.put("success",false);
returnMap.put("message",close_response.get("response_status").get("message"));
}
}
}
}
return returnMap;
As demonstrated in the above sample script, after the custom function is executed, you can optionally prompt the user of the success or the failure of the action execution by including the following section in the script:
After writing the custom function, you can test it by following the steps given below:
You can similarly test custom functions added to the Custom Menu of Assets and Changes.
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.
Similarly, you can use info to debug code and print output of custom functions used in Custom Menu of Assets and Changes.
On the custom function list view page, you can use the Actions menu to bulk disable/enable and delete custom functions.

You can also view a custom function by simply clicking it. To perform actions on individual custom functions, use the Settings icon beside each custom function.
