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.
To learn the built-in functions of the Number data type, click here.
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. Some of the frequently used built-in functions are:
zoho.currentdate - Returns the current date
zoho.currenttime - Returns the current time
To convert a date from the default format to other formats, use the following syntax:
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:
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:
Alternately, you can first declare the variable and then specify its value.
Collection stores an array of data. You can use the Collection data type to store key-value pairs as well. The collection data type employs the following syntax:
Alternately, you can first declare the variable and then specify its value.
To iterate through Collection, use 'for each' as shown below:
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'.
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:
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 Cloud to any third-party applications. By including Connections in your API calls, you can further simplify the authentication process involved in making the API calls.
ServiceDesk Plus Cloud REST APIs enable you to perform all operations that you execute through the web client. To understand the APIs available in ServiceDesk Plus Cloud and their structures, refer to the V3 API documentation.
Write custom functions in the following syntax to trigger API calls within ServiceDesk Plus:
1. Get the list of requests in the IT help desk
2. Fetch the first 50 requests created in the application that are currently open
3. Create a request with the subject 'New Issue'
In the above sample, the API response in the 'resp' variable will be in JSON format since ServiceDesk Plus Cloud 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.
Write custom functions in the following syntax to trigger API calls to any external applications:
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.
<CONNECTION_LINK_NAME>: Provide the link name generated for the third-party application authorized through Connections.
<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.
Let's consider a sample API call for tweeting on Twitter. The steps to make this API call are as follows:
Step 1: Set up the Connection with Twitter. Let's say the link name generated for this Connection is 'twitter_office'.
Step 2: Trigger an API call by using the the link name generated ('twitter_office', in this case).
Some services require parameters to be passed as raw data in body instead of key-value pairs. You can convert such parameters to string by using 'toString()'.
Let's consider the sample discussed above. If the API requires parameters to be passed as raw data in body, the following syntax must be used: