Deluge - A Programming Language

Deluge - A Programming Language

Overview 

Deluge, or Data Enriched Language for the Universal Grid Environment is Zoho's proprietary scripting language bundled with AssetExplorer Cloud. It is a high-level language that helps non-programmers code without any training. Unlike traditional programming languages, Deluge requires fewer lines of code to execute complex actions.

Deluge supports data types, conditional statements, loops, functions, return statements, and comments that are comparable to other popular programming languages, such as C++, Python, Java, JavaScript, or Swift.

Using Deluge, you can convert complex business logic to functional workflows and automate your process. The Deluge Script Editor provides a drag-and-drop user interface to add Deluge scripts without the need to learn or remember the Deluge syntax and functions.
In AssetExplorer Cloud , Deluge comes with built-in functions that help you save time and effort, which otherwise might be spent on writing each function from scratch.

How Deluge Scripting is Used in AssetExplorer Cloud     

Using Deluge scripting, you can build custom functions that can manipulate data within AssetExplorer Cloud and other external applications. Custom functions help simplify complex, multi-step actions through program scripts that you can write and execute.

Custom functions are used in automations such as business rules, triggers, and timer actions. You can use custom functions automate complex workflows, customize business processes, and integrate AssetExplorer Cloud with external applications.

Basic Concepts of Deluge        

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.
 

Data Types     

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.

Text     
  1. myText = "Hello World!"; 
To learn the built-in functions of the Text data type, click here.

Number     
  1. number = -123.4; 
To learn the built-in functions of the Number data type, click here.
 
Boolean     
  1. result = true;
  2. result = false; 

Date/Time     
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:
  1. date='1-Jan-1990 20:50:36';
  2. 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:
  1. date='1-Jan-1990 20:50:36';
  2. 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.

Map     
The Map data type allows you to store key-value pairs as demonstrated below:
  1. userEmail = {"john":"john@manageengine.com", "peter":"peter@manageengine.com"};
  2. userEmail.put("Andrew", "andrew@manageengine.com"); //a key-value pair will be added.
  3. emailOfJohn = userEmail.get("john"); //value of 'emailOfJohn' will be 'john@manageengine.com'. 

Alternately, you can first declare the variable and then specify its value.
  1. userEmail = map();
  2. userEmail.put("john","john@manageengine.com");
  3. emailOfJohn = userEmail.get("john"); 

Collection     
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:
  1. userNames = {"john", "peter"}; 
Alternately, you can first declare the variable and then specify its value.
  1. userNames = Collection();
  2. userNames.put("john");
  3. userNames.put("peter"); 
To iterate through Collection, use 'for each' as shown below:
  1. for each <myvariable> in <collection>
  2. {
  3. Sample  
  4.  userNames = {"john","peter"};
  5. for each name in userNames{
  6. 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.

Typecasting     
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'.
  1.  dateInCalendar = '01/02/2000';
  2. monthAsString =
  3. dateInCalendar.subString(3,5);
  4. monthAsNumber =
  5. monthAsString.toNumber();
  6. info monthAsNumber; 
After debugging, you will get the following response:
 2 
To learn more built-in functions of Typecasting, click here.

Condition     
Deluge supports if and else if statements in the following syntax:
  1.  if ( <expression> )
  2. {
  3. }
  4. else if ( <expression> )
  5. {
  6. }
  7. else
  8.  } 
  9. Sample  
  10.  a=10;
  11. b=20;
  12. c=30;
  13. if( a > b && a > c){
  14. info "a is big";
  15. }
  16. else if ( b > c && b >a ){
  17. info "b is big";
  18. }
  19. else{
  20. info "c is big";
You will get the following response after debugging the above piece of code:
 c is big 

Deluge for API Calls       

Using Deluge Scripting, you can make API calls easily from AssetExplorer Cloud to any third-party applications.

AssetExplorer Cloud REST APIs enable you to perform all operations that you execute through the web client. To understand the APIs available in AssetExplorer Cloud and their structures, refer to the V3 API documentation in the application (Admin > General > API).

API calls will be triggered through the account of the support rep whose API key is configured in the custom function. You can make API calls to other service desk instances if the support rep account that you use has sufficient permissions for the API calls. 

API Calls Within AssetExplorer Cloud    

Write custom functions in the following syntax to trigger API calls within AssetExplorer Cloud:
  1.  response = invokeurl
  2. [
  3. url: "http://servername:portnumber/api/v3/<....>"
  4. type: POST\GET\PUT\DELETE
  5. parameters: {"input_data":<INPUT_DATA>}
  6. ]; 

Sample API Calls  

1. Get the list of assets in the application
  1. input_data = {"list_info":{"start_index":1,"row_count":10}};
  2. resp = invokeurl
  3. [
  4. url :"/app/"+"instance_name"+"/api/v3/assets"
  5. type:GET,
  6. parameters : {"input_data":input_data}
  7. ];
2. Fetch the first 50 assets created in the application that are currently open
  1. resp = invokeurl
  2. [
  3. url :"/app/"+"instance_name"+"/api/v3/assets"
  4. type:GET
  5. parameters: {"input_data":{"list_info":{"row_count":"50","search_criteria":{"field":"state.name","condition":"is","value":"In Store"}}}}
  6. ];
In the above sample, the API response in the 'resp' variable will be in JSON format since AssetExplorer 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.

API Calls to External Applications  

Write custom functions in the following syntax to trigger API calls to any external applications:
  1.  resp = invokeurl[
  2. url: <URL>
  3. type: <GET|POST|PUT|DELETE|PATCH>
  4. parameters: <PARAMETERS>
  5. headers: <HEADERS>
  6. files: <FILE_NAME>
  7. ]; 
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.
    • Related Articles

    • Custom Actions

      Custom actions refer to user-defined actions that can be performed on different entities across modules. For a custom action to be performed on an entity, it should be used with automation rules. Custom Actions Availability across modules Assets CMDB ...
    • Notification Rules

      Notification Rules allow you to specify conditions when an event must be alerted to users. You can configure and send notifications to users on key events that occur across modules such as Asset, CMDB, Purchase, and Contract. You can also configure ...
    • User Profile

      Update Profile Picture Click the profile icon and hover over the profile picture to update it. The picture can be in JPG, PNG, JPEG, and BMP formats. Note that the file size should not exceed 5MB. Personalize Customize your display language, time, ...
    • Sites

      Organizations may have several branches across the globe to handle various specialized activities. These branches can be located in the same or different regions, and the data from each of these branches needs to be maintained in the same place. In ...
    • Connections

      Connections are used to authenticate AssetExplorer Cloud integrations with external applications. You can use connections inside custom functions to invoke REST APIs of any third-party applications. Benefits of Connections Prevents exposure of a ...