Deluge supports data types, conditional statements, loops, functions, and return statements that are comparable to other popular programming languages, such as C++, Python, Java, JavaScript, and Swift. In the following document, we will discuss the fundamentals of Deluge in detail.
Deluge supports text, number, boolean, map, and collection data types. It also offers built-in functions for all the data types. In the Deluge Script Editor, you can display the built-in functions available for a variable by entering a period after the variable.
myText = "Hello World!";
To learn the built-in functions of the Text data type, click here.
number = -123.4;
To learn the built-in functions of the Number data type, click here.
result = true;
result = false;
This data type allows you to store date and time in a variable. Using the built-in functions of this data type, you can add days, months, time, and more.
To convert a date from the default format to other formats, use the following syntax:
date='1-Jan-1990 20:50:36';
newDate = date.toTime().toString("yyyy-MM-dd'__Hello__'HH:mm:ss");
In the above sample, newDate value will be 1990-01-01__Hello__20:50:36.
To convert a given time to milliseconds, use the following syntax:
date='1-Jan-1990 20:50:36';
timeInMs = date.toTime().toLong();
In the above sample, timeInMs value will be 631255836000.
To learn more built-in functions of the Date-Time data type, click here.
The Map data type allows you to store key-value pairs as demonstrated below:
userEmail = {"john":"john@manageengine.com", "peter":"peter@manageengine.com"};
userEmail.put("Andrew", "andrew@manageengine.com"); //a key-value pair will be added.
emailOfJohn = userEmail.get("john"); //value of 'emailOfJohn' will be 'john@manageengine.com'.
Alternately, you can first declare the variable and then specify its value.
userEmail = map();
userEmail.put("john","john@manageengine.com");
emailOfJohn = userEmail.get("john");
Collection stores an array of data. You can use the Collection data type to store key-value pairs as well. Collection employs the following syntax:
userNames = {"john", "peter"};
Alternately, you can first declare the variable and then specify its value.
userNames = Collection();
userNames.put("john");
userNames.put("peter");
To iterate through Collection, use 'for each' as shown below:
for each <myvariable> in <collection>
{
}
userNames = {"john","peter"};
for each name in userNames{
info "Name is" + name;
}
After debugging, you will get the following response:
Name is john
Name is peter
To learn the built-in functions of Collection, click here.
Deluge offers various functions to convert a variable from one data type to another.
Let's consider a sample that gets month as a number from a string called 'dateInCalendar'.
dateInCalendar = '01/02/2000';
monthAsString =
dateInCalendar.subString(3,5);
monthAsNumber =
monthAsString.toNumber();
info monthAsNumber;
After debugging, you will get the following response:
2
To learn more built-in functions of Typecasting, click here.
Deluge supports if and else if statements in the following syntax:
if ( <expression> )
{
}
else if ( <expression> )
{
}
else
{
}
a=10;
b=20;
c=30;
if( a > b && a > c){
info "a is big";
}
else if ( b > c && b >a ){
info "b is big";
}
else{
info "c is big";
}
You will get the following response after debugging the above piece of code:
c is big
Using Deluge Scripting, you can make API calls easily from ServiceDesk Plus to any third-party applications.
ServiceDesk Plus REST APIs enable you to perform all operations that you execute through the web client. To understand the APIs available in ServiceDesk Plus and their structures, refer to the V3 API documentation in the application (Admin >> General >> API).
Write custom functions in the following syntax to trigger API calls within ServiceDesk Plus:
response = invokeurl
[
url: "http://servername:portnumber/api/v3/<....>"
type: POSTGETPUTDELETE
parameters: {"input_data":<INPUT_DATA>,"TECHNICIAN_KEY":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","PORTALID":<HELPDESKID>}
];
1. Get the list of requests in the IT help desk
resp = invokeurl
[
url: "http://servername:portnumber/api/v3/requests"
type:GET
parameters: {"TECHNICIAN_KEY":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","PORTALID":<HELPDESKID>}
];
2. Fetch the first 50 requests created in the application that are currently open
resp = invokeurl
[
url: "http://servername:portnumber/api/v3/requests"
type:GET
parameters: {"input_data":{"list_info":{"row_count":"50","search_criteria":{"field":"status.name","condition":"is","value":"Open"}}},"TECHNICIAN_KEY":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","PORTALID":<HELPDESKID>}
];
3. Create a request with the subject 'New Issue'
resp = invokeurl
[
url: "http://servername:portnumber/api/v3/requests"
type: POST
parameters: {"input_data":{"request":{"subject":"new issue"}},"TECHNICIAN_KEY":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","PORTALID":helpdeskID}
];
In the above sample, the API response in the 'resp' variable will be in JSON format since ServiceDesk Plus v3 API responses are in JSON format. In further lines of code, you can use the 'resp' variable like any other variable. The API response must be treated as the 'Map' data type.
Integration tasks
Integration tasks are a set of predefined functions in deluge scripting that simplify how users interact with APIs.
Earlier, API calls to ServiceDesk Plus were made using the invokeURL task, which sent external HTTP requests similar to those from third-party applications. With integration tasks, these API calls are now executed internally using the framework’s built-in methods, eliminating the need to construct HTTP connections manually or traverse the network layer.
Supported Modules: Web tab Custom Modules with custom functions enabled, Requests, Problems, Changes, Projects, and Releases.
Syntax
The syntax for an integration task is as follows:
sdp*.<poral_short_name>.<entity*>.<action*>(<parameters*>);
The deluge editor’s auto-complete feature assists by suggesting relevant entities and actions as you type.
The parameter structure is as shown below:
|
Element |
Description |
|
* |
Indicates mandatory parameters in the syntax. |
|
<portal_short_name> |
The short name of the instance whose module data you want to access or modify. Learn more. |
|
<entity> |
The name of the module whose data you want to access or modify. If the entity is nested, specify it in hierarchical order, with parent entity names separated by dots. |
|
<action> |
The operation to be performed on the entity (for example: create, update, or get). |
|
<parameters> |
Comma-separated values required to perform the action. All parameters must be specified. Use NULL for non-mandatory parameters. |
Note: You can either use the portalID or the portal short name.
|
OPERATION TYPE |
PARAM STRUCTURE |
|
HTTP POST |
sdp.<entity>.<action>( inputData, portalID, <connection> ); Example: sdp.requests.add(input_data, 901, "admin" ); sdp.<parent_entity>.<entity>.<action>( parentURL, inputData, portalID, <connection> ); Example: sdp.cm_cm1s.cm_custom_sub_entities.add("/cm_cm1s/1", input_data, null, "sdpop" ); sdp.<poral_short_name>.<entity>.<action> ( inputData, <connection> ); Example: sdp.hr.cm_custom_records.add(inputData , "admin" ); sdp.<poral_short_name>.<parent_entity>.<entity>.<action>( parentURL, inputData, <connection> ); Example: sdp.as1.changes.tasks.comments.add("/changes/100000012/tasks/100000066" , inputData, "admin" ); |
|
HTTP PUT |
sdp.<entity>.<action>( entityID, inputData, portalID, <connection> ); Example: sdp.releases.assign(100000087, inputData, 301, "admin_integ" ); sdp.<parent_entity>.<entity>.<action>( parentURL, entityID, inputData, portalID, <connection> ); Example: sdp.projects.members.edit("/projects/3", ids, inputData, 1, "admin_integ" ); sdp.<poral_short_name>.<entity>.<action> ( entityID, inputData, <connection> ); Example: sdp.hr.changes.close_change(200000009, inputData, "admin_integ" ); sdp.<poral_short_name>.<parent_entity>.<entity>.<action>( parentURL, entityID, inputData, <connection> ); Example: sdp.fh.problems.tasks.mark("/problems/100000004", 100000001, inputData, "admin_integ" ); |
|
HTTP DELETE |
sdp.<entity>.<action>( entityID, portalID, <connection> ); Example: sdp.requests.move_to_trash(IDs, null, "admin_integ" ); sdp.<parent_entity>.<entity>.<action>( parentURL, entityID, portalID, <connection> ); Example: sdp.problems.tasks.comments.delete("/problems/100000001/tasks/100000001", 11, 301, "admin" ); sdp.<poral_short_name>.<entity>.<action> ( entityID, <connection> ); Example: sdp.bla.cm_cm1s.delete(100000001, "admin_integ" ); sdp.<poral_short_name>.<parent_entity>.<entity>.<action>( parentURL, entityID, <connection> ); Example: sdp.fh.releases.tasks.delete("/releases/100000004", 100000001, "admin_integ" ); |
|
GET CONVENIENCE OPERATIONS |
sdp.<entity>.<action>( entityID, inputData, portalID, <connection> ); Example: sdp.requests.get_approval_notification_content(1, null, null, "sdpop" ); sdp.<parent_entity>.<entity>.<action>( parentURL, entityID, inputData, portalID, <connection> ); Example : sdp.projects.milestones.tasks.worklogs.get_time_spent("/projects/300000004/milestones/300000003/tasks/3000000010", 300000001, inputData, 901, "admin_integ" ); sdp.<poral_short_name>.<entity>.<action> ( entityID, inputData, <connection> ); Example: sdp.hr.changes.get_permissions(100000001, null, "sdpop" ); sdp.<poral_short_name>.<parent_entity>.<entity>.<action>( parentURL, entityID, inputData, <connection> ); Example: sdp.fh.requests.worklogs.summary("/requests/300000003", 300000045, null, "admin_integ" ); |
|
ENTITY SINGE GET |
sdp.<entity>.get( entityID, portalID, <connection> ); Example : sdp.requests.get(300000045, 901, "admin" ); sdp.<parent_entity>.<entity>.get( parentURL, entityID, portalID, <connection> ); Example : sdp.projects.members.get("/projects/3", 5, 1, "admin_integ" ); sdp.<poral_short_name>.<entity>.get( entityID, <connection> ); Example : sdp.bla.cm_cm1s.get(100000001, "admin_integ" ); sdp.<poral_short_name>.<parent_entity>.<entity>.get( parentURL, entityID, <connection> ); Example : sdp.fh.requests.worklogs.get("/requests/300000003", 300000045, "admin_integ" ); |
|
GET LIST |
sdp.<entity>.get_list( inputData, portalID, <connection> ); Example : sdp.requests.get(inputData, 901, "admin" ); sdp.<parent_entity>.<entity>.get_list( parentURL, inputData, portalID, <connection> ); Example: sdp.projects.members.get("/projects/3", null, 1, "admin_integ" ); sdp.<poral_short_name>.<entity>.get_list( inputData, <connection> ) sdp.<poral_short_name>.<parent_entity>.<entity>.get_list( parentURL, inputData, <connection> ); Example : sdp.fh.requests.worklogs.get("/requests/300000003", inputData, "admin_integ" ); |
Parameter syntax
|
Parameter |
Type |
Description |
|
parentURL |
Text |
Parent entity details in URL format, excluding /api/v3 and the actual entity endpoint. Example: https://zylker.com/api/v3/requests/1/tasks/1, the parentURL can be specified as /requests/1. |
|
entityID |
Number, List |
The ID of the entity on which the action is performed. |
|
portalID |
Number |
Use this parameter if portal name is not specified in the syntax. All portals for which the user has permission are listed in auto-suggest. Retired portals and portals with expired licenses are not shown. Use Null or 1 for the IT portal, and the respective portal IDs for other portals. API calls can also be made across portals. |
|
inputData |
JSON, Map |
Input data provided in JSON format. |
|
connection |
Text |
Connection link name. Users can also create, authenticate, or manage connections directly from the custom functions page using the Manage option in the auto-suggest or the Connections button at the top-right corner. |
Write custom functions in the following syntax to trigger API calls to any external applications:
resp = invokeurl[
url: <URL>
type: <GET|POST|PUT|DELETE|PATCH>
parameters: <PARAMETERS>
headers: <HEADERS>
files: <FILE_NAME>
];
Use the following pointers to fill out the custom function details:
<URL>: Provide your API URL.
<PARAMETERS>: Specify the parameters of your API.
<HEADERS>: Provide the authorization details of the third-party application. For example, if your API accepts 'authtoken', then provide the authtoken generated for the third party application.
<FILE_NAME>: If you are triggering an API to submit a file (received from another API's response), specify the file name in this space.
<Connection>: Select stored authorization details instead of hard-coding the credentials. You can also create and manage connections directly from the Custom Function page:
* To create new connections, click Manage or Connections.
* To use existing connections, click <connection> and choose the required connection from the auto-suggestions.
