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   

    myText = "Hello World!";

     

    To learn the built-in functions of the Text data type, click here.

     

    Number   

    number = -123.4;

     

    To learn the built-in functions of the Number data type, click here.

     

    Boolean   

    result = true;

    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:

     

    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.

     

    Map   

    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   

    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>

    {

    }

     

    Sample   

    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.

     

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

     

    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.

     

    Condition   

    Deluge supports if and else if statements in the following syntax:

     

    if ( <expression> )

    {

    }

    else if ( <expression> )

    {

    }

    else

    {
    }

     

    Sample  

    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

     

    Deluge for API Calls   

    Using Deluge Scripting, you can make API calls easily from ServiceDesk Plus MSP to any third-party applications.

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

    Note:

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

     

    API Calls Within ServiceDesk Plus MSP 

    Write custom functions in the following syntax to trigger API calls within ServiceDesk Plus MSP:

     

    response = invokeurl

    [

    url: "http://servername:portnumber/api/v3/<....>"

    type: POST\GET\PUT\DELETE

    parameters: {"input_data":<INPUT_DATA>,"TECHNICIAN_KEY":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","PORTALID":<HELPDESKID>}

    ];

     

    Sample API Calls   

    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 MSP 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:

    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.

    If you are triggering an API to submit a file (received from another API's response), specify the file name in this space.

     

     

     

     

     

     

     

     

    Copyright © 2017, ZOHO Corp. All Rights Reserved.