在开发自定义部件时,您可以使用 JS API 函数来调用您的部件或任何第三方应用程序。
JS API 必须从自定义部件中调用。
通过建立产品与自定义部件之间的连接,初始化 JS SDK 并定义实用功能。 SDP.init() 将自定义部件与其他 JS 应用程序接口连接起来,使用户可以看到该部件。 只有在初始化完成后,才会定义其他 JS API。
返回值:
Promise - Resolved with API Success or Rejected with API Failure
语法:
SDP.init().then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
API 调用 | 成功响应 |
SDP.init().then(function(response) { | { "meta": { "module": "request", "module_entity_id": "4", "location": "request.detail.rightpanel", "instance": { "appid": 1 }, "userLanguage": "en_US", "userLocale": "en_US", "userType": "Technician", "userId": 5, "userName": "administrator", "isSDAdmin": true, "widget": { "id": "2103", "name": "teamviewer1", "description": "A widget that allows technicians to gain remote access to devices across different platforms.", "custom_widget": { "id": "2702" } } }, "uniqueID": "3b12a30c-2c4b-48cd-afe0-c16d7eab9abd", "location": "request.detail.rightpanel" } |
从服务器上获取部件数据,如 URL 或自定义部件中的任何输入数据。您还可以使用此函数从自定义部件执行跨门户调用。请注意,使用此函数只能调用 SDP V3 API 调用。
示例:使用人力资源门户中的 URL 访问 IT 门户中的请求。
参数
名称 | 类型 | 描述 | |||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
* 必填参数
返回:
Promise - Resolved with API Success or Rejected with API Failure.
API 调用 | 成功响应 | 失败响应 |
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 V3 API。
参数:
名称 | 类型 | 描述 | |||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
* 必填参数
返回:
Promise - Resolved with API Success or Rejected with API Failure. Refer API documentation for success/failure response formats.
语法:
SDP.add(options).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
API 调用 | 成功响应 | 失败响应 |
SDP.add({
| //Refer API documentation for success response. | //Refer API documentation for failure response. |
通过提及实体 ID,从自定义部件编辑服务器中的数据。您还可以使用此函数从自定义部件执行跨门户调用。请注意,使用此功能只能调用 SDP V3 API。
您还可以使用此函数执行批量编辑。
参数
名称 | 类型 | 描述 | |||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
* 必填参数
返回:
Promise - Resolved with API Success or Rejected with API Failure.
语法:
SDP.edit(options).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
API 调用 | 成功响应 | 失败响应 |
SDP.edit({
| //Refer API documentation for success response. | //Refer API documentation for failure response. |
通过提及实体 ID,从自定义部件中删除服务器中的数据。您也可以使用此函数从自定义部件执行跨门户调用。请注意,使用此函数只能调用 SDP V3 API。
目前,您只能使用此函数删除 ServiceDesk Plus 中的自定义模块实体。
参数:
名称 | 类型 | 描述 | |||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
* 必填参数
返回值:
Promise - Resolved with API Success or Rejected with API Failure.
API 调用 | 响应成功 | 响应失败 |
SDP.del({ url:"/cm_nat/", ids:"307" });
| //Refer API documentation for success response. | //Refer API documentation for failure response. |
使用自定义部件的授权令牌调用外部 api。
参数
名称 | 类型 | 描述 | ||||||||||||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
API 调用 | 响应成功 | 响应失败 |
SDP.connect({ url: "https://webapi.teamviewer.com/api/v1/sessions", headers: { "Content-Type": "application/json" }, method: "post", data: JSON.stringify({ "groupname": "SDPOnDemand", "waiting_message": "Please wait for the technician to join session.", }), connection: connection_link_name });
| Based on the third party API | Based on the third party API |
刷新自定义部件。
语法
SDP.refreshWidget()
在部件中执行操作时显示提示框。
参数:
名称 | 类型 | 描述 | ||||||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
API 调用 | 响应成功 | 响应失败 |
SDP.show_alert({ message:"widget data successfully stored", alert_type:"success" })
| Displays an alert message | Message cannot be empty |
在部件中执行操作时,显示带有给定信息和按钮的确认对话框。
参数:
名称 | 类型 | 描述 | ||||||||||||
options* | 对象 | 包含 API 详细信息的对象。
|
API 调用 | 响应成功 | 响应失败 |
SDP.show_confirm({ label:"yes" } label:"no" }],
| A confirmation screen with Yes or No buttons is displayed. When you press any button, the corresponding value is sent as a response. |
|
显示应用程序页面的加载状态。目前,该功能仅适用于加载栏。
语法
SDP.showIndicator({
category:"loading"
})
隐藏显示的指示器。
语法
SDP.hideIndicator({
category:"loading"
})
在打开 ServiceDesk Plus 窗口的浏览器中获取与自定义部件相关的所有临时变量。
临时变量用于在有限时间内存储值,例如直到窗口重新加载。
返回值:
Promise - Resolved with Success or Rejected with Failure.
语法:
SDP.getTempVariables().then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response)})
e)
示例:
API 调用 | 成功响应 |
SDP.getTempVariables().then(function(response) { console.log(response); }).catch(function(response) { console.log(response); }); | { "key": value, } |
获取指定的临时变量。
参数:
名称 | 类型 | 描述 |
key* | 字符串 | 表示临时变量键,用于指定要获取的变量详细信息。 |
* 必填参数
返回:
Promise - Resolved with Success or Rejected with Failure.
语法:
SDP.getTempVariable(key).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response)})
示例
API 调用 | 成功响应 |
SDP.getTempVariable(“passphrase").then(function(response) { console.log(response); }).catch(function(response) { console.log(response); }); | { "key": "passphrase", "value": "*****" } |
更新与部件相关联的变量值。
这个函数在配置部件中特别有用,因为它们在用户界面中没有可以更新变量值的配置页面。
参数:
名称 | 类型 | 描述 |
key* | 字符串 | 表示要更新的变量的key值。 |
value* | - | 表示要更新到变量中的值。 如果不传递,变量值将在应用程序中重置。 |
*必填参数
返回值:
Promise - Resolved with Success or Rejected with Failure.
语法:
SDP.setTempVariable(key, value).then(function(response) { console.log(response); }).catch(function(response) { console.log(response); });
});
示例:
API 调用 | 成功响应 | 失败响应 |
SDP.setTempVariable(“admin”, “john-doe”).then(function(response) { console.log(response); }).catch(function(response) { console.log(response); }); | Variables saved in the application window successfully. | - |
从请求表中获取字段值。
参数:
名称 | 类型 | 描述 |
Field* | 字符串 | 字段的名称 |
* 必填参数
返回:
Promise - Resolved with Success or Rejected with Failure.
语法:
SDP.getValueFromForm(field).then(function(response) {
console.log(response);
}).catch(function(response) {
console.log(response);
});
示例:
API 调用 | 成功响应 | 失败响应 |
SDP.getValueFromForm(“SUBJECT").then(function(response) { console.log(response); }).catch(function(response) { console.log(response); }); | { value: “Error in connecting to certain websites/URLs” } | { message: “The requested action is not supported in this view” } |
获取加载自定义部件的实例的详细信息。
返回:
Object – Returns instance details object.
语法:
var instanceDetails = SDP.getCurrentInstance();
示例响应:
{
appdisplayname: "IT Desk"
appid: "15459854"
appname: "itdesk"
}
获取登录用户 ID。
返回:
String – Returns user ID as a string.
语法:
var userId = SDP.getCurrentUserId();
示例响应:
"1000000000087326"
获取登录用户类型(请求者/技术人员)。 请注意,该函数不会获取角色。
返回:
String – Returns user type as a string.
语法:
var userType = SDP.getCurrentUserType();
示例响应:
"Technician"
获取登录的用户名。
返回:
String – Returns user name as a string.
获取当前用户的电子邮件地址。
返回:
String – Returns user email as a string.
语法:
var userEmail = SDP.getCurrentUserEmail();
示例响应:
获取当前部件信息。
返回:
Object – Returns the widget info object.
语法:
var widgetInfo = SDP.getWidgetInfo();
示例响应:
{
"id": "120747000002587069",
"name": "Custom Widget",
"description": "",
"custom_widget": {
"id": "120747000002587067"
}
}
获取传递给部件的 widget 元。
返回:
Object – Returns the widget meta-object.
语法:
var widgetMeta = SDP.getWidgetMeta();
示例响应:
{
"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"
}
}
}
获取当前部件的位置。
返回:
String – Returns the widget location.
语法:
var location = SDP.getWidgetInvokedLocation();
响应示例:
“webtab”
获取从父部件传递过来的数据。
返回
Object – Returns the data object passed by the parent widget.
语法
var data = SDP.getDataPassedByparent();
示例
{
mode: "new_user"
}
获取调用了子 widget 的父 widget 的位置。
返回
String – Returns the parent widget location.
语法
var parentLocation = SDP.getParentLocation();
响应示例
“webtab”
获取调用了子 widget 的父 widget 的详细信息。
返回
Object – Returns the parent widget info object.
语法
var parentInfo = SDP.getParentWidgetInfo();
示例响应:
{
"id":"100000000000032273",
"name":"Sample Widget",
"description":"Sample Widget",
"custom_widget":{
"id":"100000000000032271"
}
}
返回正在加载的 Ajax 条形码 html。
语法
SDP.ajaxBar();