JavaScript Software Development Kit

JS APIs are JS functions to include various ServiceDesk Plus Cloud functionalities in the custom widget you create.

Add this JavaScript file to all the HTML/widget pages to access the JavaScript APIs from the application: https://sdpondemand.manageengine.com/scripts/v1/widget/sdpclientsdk.min.js.

The JS file must be loaded into every widget page where you want to invoke the APIs. Use the following syntax to add the JS file to the widget pages:

Syntax:

<script type="text/javascript" src="https://sdpondemand.manageengine.com/scripts/v1/widget/sdpclientsdk.min.js"></script>

 

JavaScript API  

While developing a custom widget, you can use JS API functions to invoke calls to your widget or any third-party application. This page documents the various functions that you can use to build your custom widget and its use cases.

 

JS APIs must be invoked from the custom widget.

General Functions for Custom Widgets 

SDP.init() 

Initializes the JS SDK and defines utility functions by establishing the connection between the product and the custom widget. This function acts as foundational to establish a connection between the custom widget and other JS APIs to make them visible to users. Other JS APIs will be defined only when the initialization is completed.

Returns:

Promise - Resolved with API Success or Rejected with API Failure

Syntax:  

SDP.init().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

SDP.init().then(function(response) {
    console.log(response);
}).catch(function(response) {
    console.log(response);
});

 

{
    "meta": {
        "module": "header",
        "instance": {
            "appid": "709641411",
            "appname": "widgetdev",
            "appdisplayname": "Widget Development"
        },
        "personalization": {
            "time_zone": "Asia/Kolkata",
            "time_format": "MMM d, yyyy hh:mm a",
            "date_format": "MMM d, yyyy"
        },
        "userLanguage": "en",
        "userLocale": "en_US",
        "userType": "Technician",
        "userId": "120747000000232217",
        "userName": "Widget Development",
        "userEmail": "widget_dev@sdpdev.onmicrosoft.com",
        "isSDAdmin": true,
        "widget": {
            "id": "120747000002587069",
            "name": Custom Widget ",
            "description": "",
            "custom_widget": {
                "id": "120747000002587067"
            }
        }
    },
    "uniqueID": "78d261d9-65f7-48bc-b10d-84b7e79b1285",
    "location": "webtab"
}


SDP.invokeUrl(options) 

Fetch data from integrated third-party applications. The function is mapped under various option params such as URL, method, headers, params, payload, file-id (not supported for probe-based integrations), connection pathway (probe or connection link). You can invoke 3rd party URLs directly or by using connections/probes. By default, 3rd party URLs are invoked directly if no connection or probe is set.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

url*

string

Indicates the API URL. Encode the URL if it contains space.

method

string

Indicates the method of the API call. By default “post” method is passed.

Supported methods: get, post, put, delete, and patch.

params

object

Indicates the params of the API in key-value format.

headers

object

Indicates the params of the API in key-value format.

payload

string

String to be passed in Request Body.

is_probe_connection

boolean

If set as true, the connection is established through a probe. Used to connect to Intranet sites or to establish a connection between Cloud and On-premise applications.

connectionLinkName

string

Specify the DRE connection link name. Only connections that are installed in the custom widget package can be used here. This will be considered only if “is_probe_connection” property is not true.

file_id

long

Indicates ServiceDesk Plus Cloud File ID. This option is used if an attachment needs to be uploaded to the third-party application. This property is supported only when the “connectionLinkName” is provided.

* Mandatory parameter

 

You cannot configure both probe and DRE connection to invoke a third-party application.

 

Returns:

Promise - Resolved with API Success or Rejected with API Failure.

Syntax

SDP.invokeUrl(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.invokeUrl({
    “url”: “https: //api.twitter.com/1.1/statuses/update.json”,
    “method”: “post”,
    “params”: {
        “status”: "SDP and twitter integrated"
    },
    “connectionLinkName”: “twitter”
}).then(function(response) {
    console.log(response);
}).catch(function(response) {
    console.log(response);
});

//Based on 3rd party API

//Based on 3rd party API

To use the variable directly in the invoke URL, refer here.


 

Manage Custom Widgets iFrame

SDP.openWidget(options) 

Opens a new widget as a pop-up within the custom widget.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

id*

long

Indicates the ID of the widget to be opened.

name*

string

Indicates the name of the widget to be opened.

title

string

Sets the title of the popup. If the title is not passed, the widget name will be set as the popup title.

data

object

Specifies the data to be passed to the widget that is opening.

* Mandatory parameter

 

Either ID or name parameters can be specified as an option to open the widget. If both are specified, only ID will be considered. 

 

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.openWidget(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.openWidget({
    id: "100000000000032273",
    data: {
        mode: "new_user"
    }
}).then(function(response) {
    console.log(response);
}).catch(function(response) {
    console.log(response);
});

{

message: “Widget opened successfully”

}

{

"message": "Please provide a valid widget id or name with required visibility permissions to render"

}


SDP.closeWidget() 

Closes the pop-up where the custom widget is loaded. This API is functional only if a widget is opened in a pop-up window, such as menu widget or a widget opened using the SDP.openWidget API.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.closeWidget().catch(function(response) {
	console.log(response);
});

SDP.closeWidget() call’s successful execution closes the widget popup in the window. Hence success callback is not needed for this API.

Sample:

API Call

Failure Response

SDP.closeWidget().catch(function(response) {

console.log(response);

});

{

message: “This requested action is not supported in this view”

}


SDP.resizeWidget(options) 

Resize the custom widget popup as needed. The maximum widget size allowed is 1200X800 pixels.

This API is functional only if a widget is opened in a pop-up window, such as menu widget or a widget opened using the SDP.openWidget API.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

width*

integer

Specify the required widget popup width in pixels. The maximum width for pop-up is 1200 pixels.

height*

integer

Specify the required widget popup height in pixels. Maximum height for pop-up is 800 pixels.

* Mandatory parameter

 

Either ID or name parameters can be specified as an option to open the widget. If both are specified, only ID will be considered. 

 

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.resizeWidget(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.resizeWidget({

width: 1000,

height: 500

}).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

"message": "Window resized successfully"

}

{

"message": "width is not a valid number"

}


Add/Edit/Delete Service Desk Data

SDP.get(options) 

Fetch the widget data such as URLs, or any input data in the custom widget from the server. You can also perform a cross portal call from the custom widget using this function. Note that only SDP V3 APIs can be invoked using this function.

Example: Access a request present in the IT Portal using its URL to the HR Portal.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

url*

string

Mention only the entity URL. The API context will be set automatically.

input_data

object

Specify the input data to be passed in the API call. Refer API documentation for input_data format.

portalid

long

Specify the instance ID to invoke cross-portal calls.

* Mandatory parameter

Returns:

Promise - Resolved with API Success or Rejected with API Failure. Refer API documentation for success/failure response formats.

Syntax:

SDP.get(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.get({

url: "/requests"

}).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

//Refer API documentation for success response.

//Refer API documentation for failure response.


SDP.add(options)

Add data to the server from the custom widget.  You can also perform a cross portal call from the custom widget using this function. Note that only SDP V3 APIs can be invoked using this function.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

url*

string

Mention only the entity URL. The API context will be set automatically.

input_data

object

Specify the input data to be passed in the API call. Refer API documentation for input_data format.

portalid

long

Specify the instance ID to invoke cross-portal calls.

* Mandatory parameter

Returns:

Promise - Resolved with API Success or Rejected with API Failure. Refer API documentation for success/failure response formats.

Syntax:

SDP.add(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.add({
    url: "/requests",
    input_data: {
        request: {
            subject: 'Request created from Widget'
        }
    }
}).then(function(response) {
    console.log(response);
}).catch(function(response) {
    console.log(response);
});

//Refer API documentation for success response.

//Refer API documentation for failure response.


SDP.edit(options) 

Edit data in the server from the custom widget by mentioning the entity ID. You can also perform a cross portal call from the custom widget using this function. Note that only SDP V3 APIs can be invoked using this function.

You can also perform bulk-editing using this function.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

url*

string

Mention only the entity URL. The API context will be set automatically.

input_data

object

Specify the input data to be passed in the API call. Refer API documentation for input_data format.

portalid

long

Specify the instance ID to invoke cross-portal calls.

* Mandatory parameter

Returns:

Promise - Resolved with API Success or Rejected with API Failure. Refer API documentation for success/failure response formats.

Syntax:

SDP.edit(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.edit({
    url: "/requests/100000000000032746",
    input_data: {
        request: {
            subject: 'Request created from Widget'
        }
    }
}).then(function(response) {
    console.log(response);
}).catch(function(response) {
    console.log(response);
});

//Refer API documentation for success response.

//Refer API documentation for failure response.


SDP.del(options) 

Delete data in the server from the custom widget by mentioning the entity ID.  You can also perform a cross portal call from the custom widget using this function. Note that only SDP V3 APIs can be invoked using this function.

Currently, you can use this function to delete only custom module entities in ServiceDesk Plus Cloud. 

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

url*

string

Mention only the entity URL. The API context will be set automatically.

ids

string

Entity Id. Multiple ids can be passed as a comma-separated string.

portalid

long

Specify the instance ID to invoke cross-portal calls.

* Mandatory parameter

Returns:

Promise - Resolved with API Success or Rejected with API Failure. Refer API documentation for success/failure response formats.

Syntax:

SDP.del(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.del({
    url: “/cm_webtab/100000000000032739”
}).then(function(response) {
    console.log(response);
}).catch(function(response) {
    console.log(response);
});

//Refer API documentation for success response.

//Refer API documentation for failure response.

 


SDP.refreshPage()

Refreshes the page where the widget is loaded. Note that only the page body is loaded, the application header remains untouched.

Example: If the API is called from the right panel widget in a request, the request details page completely reloads.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.refreshPage();

SDP.refreshPage() call reloads the page which in turn unloads the widget from window. Hence callback is not needed for this API.


SDP.showIndicator(options)

Displays the indicator on the application window after an operation is completed.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

category*

string

Defines the category of the indicator.

Possible categories: success/failure/info/loading

message

string

The message or information to be displayed in the indicator. This is mandatory except for Loading indicators.

timeout

integer

Defines the amount of time in milliseconds for which the indicator is displayed. You can define up to 5000 milliseconds.

This parameter is applicable to all category indicators except for the Loading indicator, which will be displayed until the SDP.hideIndicator(indicator_type) is called.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure. Success response will be received when the user clicks the action button.

Syntax:

SDP.showIndicator(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.showIndicator({

message: “Used added”

category: “success”

}).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

“message”: “Indicator displayed”

}

{

“message”: “message is not passed from the widget”

}

 


SDP.hideIndicator(indicator_type) 

Hides the displayed indicator.

Parameters:

Name

Type

Description

indicator_type

string

Defines the type of indicator to be hidden. If indicator_type is not passed, indicators or any indicator_type will be hidden.

Possible indicator_types: message/loading.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax: 

SDP.hideIndicator(indicator_type).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.hideIndicator({

indicator_type: “message”

}).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

“message”: “Indicator hidden

}

{

“message”: indicator_type is not valid”

}


SDP.showAlert(options)

Displays an alert box when an action is performed in the widget.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

title

string

Defines the title of the alert box. Default title - “Alert”.

message*

string

The message or information to be displayed in the alert box.

action

string

Defines the action button text. Default text - “Ok”.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure. Success response will be received when the user clicks the action button.

Syntax:

SDP.showAlert(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.showAlert({

title: “Probe Info”,

message: “Win2 probe has been selected.”,

action: “Ok

}).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

“index: “0”

}

{

“message”: “message cannot be null”

}


SDP.showConfirm(options)

Displays a confirm dialog box when an action is performed in the widget.

Parameters:

Name

Type

Description

options*

object

Object which contains API details.

Property

Type

Description

title

string

Defines the title of the confirm dialog. Default title - “Alert”.

message*

string

The message or information to be displayed in the confirm dialog.

mode

string

Mode is used to change the style of the alert box.

Supported Mode: attention.

Attention mode is mainly used to render warnings and alert themes.

confirm

array

Renders the passed string as action buttons - Confirm and Cancel. The buttons will be rendered in RTL order. The primary action button will be styled according to the current application theme.

If 'confirm' property is not passed,

  • The default “Yes” and “No” text will be rendered for the action buttons.
  • If attention mode is passed, “Confirm” and “Cancel” will be rendered in the warning theme.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure. Success response will be received when the user clicks the action button and contains the index of the action button.

Syntax:

SDP.showConfirm(options).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.showConfirm({

title: “Delete User”,

message: “Do you want to delete selected requester(s)?”,

confirm: [“Delete”, “Cancel”]

}).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

“index: “0”

}

{

“message”: “message cannot be null”

}


Manage Variables/Connection/Probes in Custom Widget 

SDP.getVariables() 

Fetches all the variables associated with the custom widget.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getVariables().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

SDP.getVariables().then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

[

{

"id": "100000000000032357",

"type": "string",

"secure": false,

"value": "admin",

"key": "Username"

}

]


SDP.getVariable(key) 

Fetches the details of a specified variable from the widget.

Parameters:

Name

Type

Description

key*

string

Indicates the key of variable whose details are to be fetched.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getVariable(key).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.getVariable(“admin”).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

"id": "100000000000032357",

"type": "string",

"secure": false,

"value": "john-doe",

"key": "admin"

}

{

"message": "There's no variable available with the provided key"

}


SDP.setVariable(key, value) 

Update the value of a variable associated with the widget.

This function is especially useful in Configuration Widgets since they do not have a configuration page in the UI where the variable value can be updated. 

Parameters:

Name

Type

Description

key*

string

Indicates the key of variable to be updated.

value

-

Indicated the value to be updated to the variable. If not passed, the variable value will be reset in application.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.setVariable(key, value).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.setVariable(“admin”, “john-doe”).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

"id": "100000000000032357",

"type": "string",

"secure": false,

"value": "john-doe",

"key": "admin"

}

{
    "response_status": {
        "status_code": 4000,
        "messages": [
            {
                "status_code": 4001,
                "field": "value",
                "error_xpath": "variable.value",
                "type": "failed",
                "message": "Value given for value is not valid"
            }
        ],
        "status": "failed"
    }


SDP.getTempVariables()

Fetches all temporary variables relevant to the custom widget stored in browser where the ServiceDesk Plus Cloud window is opened.

Temporary variables are used to store values for a limited time, such as until the window reloads.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getTempVariables().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

SDP.getTempVariables().then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

"passphrase": "*****"

}


SDP.getTempVariable(key)

Fetches the specified temporary variable.

Parameters:

Name

Type

Description

key*

string

Indicates the temporary variable key that specifies which variable details are to be fetched.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getTempVariable(key).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

SDP.getTempVariable(“passphrase).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

"key": "passphrase",

"value": "*****"

}


SDP.setTempVariable(key,value)

Set a temporary variable and specify a value to it.

Parameters:

Name

Type

Description

key*

string

The key of the temporary variable to be updated.

value

-

The new value to be configured with the temporary variable.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.setTempVariable(key, value).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

SDP.setTempVariable(“passphrase, “*****”).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

"message": "Variable saved in application window successfully"

}


SDP.getConnections() 

Fetches the details of all successfully installed connections that are associated with the widget.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getConnections().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

SDP.getConnections().then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{
    "connections": [
        {
            "authorize_url": "/delugeauth/authenticateConnections/Public__15459854__15421476__1000000000897261",
            "scopeDisplayString": "read, write, account",
            "serviceNumber": 104,
            "dbName": "Public",
            "groupScopeId": "1000000000118063",
            "admin": true,
            "linkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
            "revoke_url": "/delugeauth/revokeConnectionApi?sharedBy=15459854&connectionLinkName=2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello&isUserDefined=false&zohoServiceName=SDPOnDemand",
            "scope_details": [
                {
                    "Scope Name": "read",
                    "Scope Value": "read"
                }
            ],
            "scope": [
                "read"
            ],
            "logo": "trello.png",
            "connectedServiceId": "1000000000897261",
            "absolute_logo_url": "https://js.zohostatic.com/dre/images/connections/logos/trello.png",
            "displayLinkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",
            "serviceName": "Trello",
            "connected": false,
            "versionId": "1000000000118047",
            "scoped": true,
            "adminZuId": 15421476,
            "sharedBy": 15459854,
            "userAccess": false,
            "connectionName": "Automation Widget-trello",
            "isUserDefinedService": false,
            "status": 2,
            "serviceLinkName": "trello"
        }
    ],
    "status": true
}


SDP.getConnection(connectionLinkName)

Fetches the details of a specific connection that is associated with the widget.

Parameters:

Name

Type

Description

connectionLinkName*

string

Specifies which connection details are to be fetched.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getConnection(connectionLinkName).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.getConnection(“trello).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

"connections": {

"authorize_url": "/delugeauth/authenticateConnections/
 Public__15459854__15421476__1000000000897261",

"scopeDisplayString": "read, write, account",

"serviceNumber": 104,

"dbName": "Public",

"groupScopeId": "1000000000118063",

"admin": true,

"linkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",

"revoke_url": "/delugeauth/revokeConnectionApi?sharedBy=15459854&connectionLinkName=2c3d9619-
bcea-459d-a1c8-b3b76c393fb9-15459854trello&isUserDefined=
false&zohoServiceName=SDPOnDemand",

"scope_details": [

{

"Scope Name": "read",

"Scope Value": "read"

}

],

"scope": [

"read"

],

"logo": "trello.png",

"connectedServiceId": "1000000000897261",

"absolute_logo_url": "https://js.zohostatic.com/dre/images/connections/logos/trello.png",

"displayLinkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb9-15459854-trello",

"serviceName": "Trello",

"connected": false,

"versionId": "1000000000118047",

"scoped": true,

"adminZuId": 15421476,

"sharedBy": 15459854,

"userAccess": false,

"connectionName": "Automation Widget-trello",

"isUserDefinedService": false,

"status": 2,

"serviceLinkName": "trello"

},

"status": true

}

{

"response_status": {

"status_code": 4000,

"messages": [

{

"status_code": 4001,

"type": "failed",

"message": "No Connection available in the given link name"

}

],

"status": "failed"

}

}

SDP.authorizeConnection(connectionLinkName) 

Authorizes the widget's connection by generating a token to the DRE (Deluge Runtime Environment) server. By default, users with permissible roles can authorize connections from the Setup. However, any user can use this JS API to authorize a widget's connection if they don't have access to Setup.

To fetch the post-authorization status, use an event listener to confirm if the authorization is complete

Parameters:

Name

Type

Description

connectionLinkName*

string

Specifies the connection to be authorized.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.authorizeConnection(connectionLinkName).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.authorizeConnection(“trello”).
then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

"connections": {

"authorize_url": "/delugeauth/authenticateConnections/Public__15459
854__15421476__1000000000897261",

"scopeDisplayString": "read, write, account",

"serviceNumber": 104,

"dbName": "Public",

"groupScopeId": "1000000000118063",

"admin": true,

"linkName": "2c3d9619-bcea-459d-a1c8-b3b76c393fb
9-15459854-trello",

"revoke_url": "/delugeauth/revokeConnectionApi?sharedBy=15459854&connectionLinkName=2c3d9619-bc
ea-459d-a1c8-b3b7
6c393fb9-15459854-trello&isUserDefined=false&zohoServiceName=SDPOnDemand",

"scope_details": [

{

"Scope Name": "read",

"Scope Value": "read"

}

],

"scope": [

"read"

],

"logo": "trello.png",

"connectedServiceId": "1000000000897261",

"absolute_logo_url": "https://js.zohostatic.com/dre/images/connections
/logos/trello.png",

"displayLinkName": "2c3d9619-bcea-459d-a1c8-b3b76
c393fb9-15459854-trello",

"serviceName": "Trello",

"connected": false,

"versionId": "1000000000118047",

"scoped": true,

"adminZuId": 15421476,

"sharedBy": 15459854,

"userAccess": false,

"connectionName": "Automation Widget-trello",

"isUserDefinedService": false,

"status": 2,

"serviceLinkName": "trello"

},

"status": true

}

{

"response_status": {

"status_code": 4000,

"messages": [

{

"status_code": 4001,

"type": "failed",

"message": "No Connection available in the given link name"

}

],

"status": "failed"

}

}


SDP.revokeConnection(connectionLinkName)

Revokes the widget's connection.

To fetch the status post revoking the connection, use an event listener to confirm if the revoke was complete.

Parameters:

Name

Type

Description

connectionLinkName*

string

Specifies the connection to be revoked.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.revokeConnection(connectionLinkName).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.revokeConnection(“trello).
then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

    "response": "Connection revoked successfully"

}

{

"response_status": {

"status_code": 4000,

"messages": [

{

"status_code": 4004,

"type": "failed",

"message": "Connection revoked already"

}

],

"status": "failed"

}

}


SDP.getProbeDetails() 

Fetches the details of the probe that is currently configured with the widget. If no probe is configured for the custom widget, the promise will be rejected.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getProbeDetails().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.getProbeDetails().then
(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

"name": "ADMP Probe",

"id": "120747000002326212"

}

{

"response_status": {

"status_code": 4000,

"messages": [

{

"status_code": 4004,

"type": "failed",

"message": "No probe is configured to this widget"

}

],

"status": "failed"

}

}


SDP.setProbeId(probeId)

Associates the probe with the custom widget.

Parameters:

Name

Type

Description

probeId

long

The ID of the probe to be associated. If not set, the previous probe association will be removed.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.setProbeId(probeId).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.setProbeId(“100000000000032742”).
then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

"status_code": 2000,

"type": "success",

"message": "Probe id for the widget updated"

}

{

"response_status": {

"status_code": 4000,

"messages": [

{

"status_code": 4001,

"type": "failed",

"message": "Please provide a valid probe id"

}

],

"status": "failed"

}

}


APIs exclusive to Add/Edit Request/Problem/Change/Release Form

SDP.showWidget() 

Displays the widgets that are hidden by default in the request/problem/change/release form right panel. You can call this API as per your requirements.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.showWidget().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.showWidget().then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

message: “The requested action performed successfully.”

}

{

message: “This requested action is not supported in this view”

}


SDP.hideWidget() 

Hides the widgets that are displayed in the right panel of the request/problem/change/release form. You can call this API as per your requirements.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.hideWidget().then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.hideWidget().then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

message: “The requested action performed successfully.”

}

{

message: “This requested action is not supported in this view”

}


SDP.setBadgeCount(count) 

Displays the provided count as a badge near the widget name displayed on the request/change form. This count corresponds to a certain value that is used to notify the users, such as available entities or number of options that can be selected.

Parameters:

Name

Type

Description

count

integer

The value to be displayed on the badge. If not passed, the badge will be hidden in the UI.

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.setBadgeCount(count).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.setBadgeCount(10).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

message: “The requested action performed successfully.”

}

{

message: “This requested action is not supported in this view”

}


SDP.getValueFromForm(field) 

Fetches a field value from the request/change form.

Parameters:

Name

Type

Description

field*

string

The name of the field

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.getValueFromForm(field).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.getValueFromForm(“subject”).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

{

value: “Error in connecting to certain websites/URLs”

}

{

message: “This requested action is not supported in this view”

}


SDP.setValueInForm(field, value)  

Sets a field value in the request/change form.

Parameters:

Name

Type

Description

field*

string

The name of the field.

value

string

The new value to be set in the field. If not passed, the existing value will be removed.

* Mandatory parameter

Returns:

Promise - Resolved with Success or Rejected with Failure.

Syntax:

SDP.setValueInForm(field, value).then(function(response) {
	console.log(response);
}).catch(function(response) {
	console.log(response);
});

Sample:

API Call

Success Response

Failure Response

SDP.setValueInForm(“subject”, “Error in connecting to certain websites/URLs”).then(function(response) {

console.log(response);

}).catch(function(response) {

console.log(response);

});

 

{

"message": "The requested action performed successfully"

}

{

message: “This requested action is not supported in this view”

}


Fetch Custom Widget/User Details  

SDP.getCurrentInstance();

Fetches the details of the instance where the custom widget is loaded.

Returns:

Object – Returns instance details object.

Syntax:

var instanceDetails = SDP.getCurrentInstance();

Sample Response:

{

   appdisplayname: "IT Desk"

   appid: "15459854"

   appname: "itdesk"

}


SDP.getCurrentUserId(); 

Fetches the logged-in user ID.

Returns:

String – Returns user Id as a string.

Syntax:

var userId = SDP.getCurrentUserId();

Sample Response:

"100000000000032197"


SDP.getCurrentUserType();

Fetches the logged-in user type (requester/technician). Note that this function does not fetch roles.

Returns:

String – Returns user type as a string.

Syntax:

var userType = SDP.getCurrentUserType();

Sample Response:

"Technician"


SDP.getCurrentUserName();

Fetches the logged-in user name.

Returns:

String – Returns user name as a string.

Syntax:

var userName = SDP.getCurrentUserName();

Sample Response:

"John Doe"


SDP.getCurrentUserEmail();

Fetches the email address of the current user.

Returns:

String – Returns user email as a string.

Syntax:

var userEmail = SDP.getCurrentUserEmail();

Sample Response:

"johndoe@somecompany.com"


SDP.getWidgetInfo();

Fetches the current widget info.

Returns:

Object – Returns the widget info object.

Syntax:

var widgetInfo = SDP.getWidgetInfo();

Sample Response:

{
    "id": "120747000002587069",

    "name": "Custom Widget",

    "description": "",

    "custom_widget": {

        "id": "120747000002587067"

    }

}


SDP.getWidgetMeta();

Fetches the widget meta passed to the widget.

Returns:

Object – Returns the widget meta-object.

Syntax:

var widgetMeta = SDP.getWidgetMeta();

Sample Response:

{

    "module": "header",

    "instance": {

        "appid": "709641411",

        "appname": "widgetdev",

        "appdisplayname": "Widget Development"

    },

    "personalization": {

        "time_zone": "Asia/Kolkata",

        "time_format": "MMM d, yyyy hh:mm a",

        "date_format": "MMM d, yyyy"

    },

    "userLanguage": "en",

    "userLocale": "en_US",

    "userType": "Technician",

    "userId": "120747000000232217",

    "userName": "Widget Development",

    "userEmail": "widget_dev@sdpdev.onmicrosoft.com",

    "isSDAdmin": true,

    "widget": {

        "id": "120747000002587069",

        "name": "Custom Widget",

        "description": "",

        "custom_widget": {

            "id": "120747000002587067"

        }

    }

}


SDP.getWidgetInvokedLocation();

Fetches the location of the current widget.

Returns:

String – Returns the widget location.

Syntax:

var location = SDP.getWidgetInvokedLocation();

Sample Response:

“webtab”


SDP.getDataPassedByparent();

Fetches the data passed from the parent widget to the child widget by the user when the child widget is opened as a pop-up. The data fetched will be passed only after the SDP.openWidget() is called.

Returns:

Object – Returns the data object passed by the parent widget.

Syntax:

var data = SDP.getDataPassedByparent();

Sample:

{

mode: "new_user"

}


SDP.getParentLocation();

Fetches the location of the parent widget that has called the child widget.

Returns:

String – Returns the parent widget location.

Syntax:

var parentLocation = SDP.getParentLocation();

Sample Response:

“webtab”


SDP.getParentWidgetInfo();

Fetches the details of the parent widget which has called the child widget.

Returns:

Object – Returns the parent widget info object.

Syntax:

var parentInfo = SDP.getParentWidgetInfo();

Sample Response:

{

  "id":"100000000000032273",

  "name":"Sample Widget",

  "description":"Sample Widget",

  "custom_widget":{

   "id":"100000000000032271"

  }

}


Event Listeners 

Event Listeners are functions that are called when a specific event occurs. They are initialized when the widget is loaded. The following event listeners are invoked to all widgets in ServiceDesk Plus Cloud when the DRE connection is authorized or revoked:

Listener Syntax

Description

Sample Response

SDP.on("AuthorizeConnection", function(response){

console.log(response);

});

 

Invoked when the connection is authorized successfully.

{

"appId": "deeed61e-c6e6-4d8f-b50b-e45056e77f5b-709641411",

"connectionId": 5000000027171221,

"statusMessage": "Connection Authenticated Successfully",

"status": true

}

SDP.on("RevokeConnection", function(response){

console.log(response);

});

 

Invoked when the connection is revoked successfully.

{

"response": "Connection revoked successfully"

}

SDP.on("SubjectChange", function(response){

console.log(response);

});

 

Invoked when the subject is changed in the request/change form.

Error in connecting to certain websites/URLs