forked from ServiceNowDevProgram/code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI Action script.js
More file actions
28 lines (28 loc) · 997 Bytes
/
UI Action script.js
File metadata and controls
28 lines (28 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Demo- OnClick function to execute
function demo() {
var ga = new GlideAjax('sn_hr_core.close_items');
ga.addParam('sysparm_name', 'getRelatedItems');
ga.addParam('sysparm_case_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
// If there exist related items
var items = JSON.parse(response);
if (items.length > 0) {
var msg = "This case has related items:\n";
items.forEach(function(item) {
msg += "- " + item.type + ": " + item.number + "\n";
});
msg += "\nDo you want to close them as well?";
if (confirm(msg)) {
// close current HR case
g_form.setValue('state', '3');
g_form.save();
}
} else {
// If no related item is associated
if (confirm("No related items found. Close this case?")) {
g_form.setValue('state', '3');
g_form.save();
}
}
});
}