Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Scenario:-

Table: HR Case

Create a form button named "Check related item and Close Complete" feature and list down the related child HR cases and HR tasks
in the pop-up message.
Upon confirmation, it will close the current case and other listed items.

This will help in reducing the manual effort of closing items manually.

Scripts:
Client UI script to handle the confirmation popup and state of current case.

GlideAJAX enabled script include to fetch the data and close the related items.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var close_item = Class.create();
close_item.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getRelatedItems: function() {
var caseId = this.getParameter('sysparm_case_id');
var results = [];

// Get child HR cases
var childCases = new GlideRecord('sn_hr_core_case');
childCases.addQuery('parent', caseId);
childCases.query();
while (childCases.next()) {
results.push({ type: 'HR Case', number: childCases.getValue('number') });
}

// Get tasks
var tasks = new GlideRecord('sn_hr_core_task');
tasks.addQuery('hr_case', caseId);
tasks.query();
while (tasks.next()) {
results.push({ type: 'HR Task', number: tasks.getValue('number') });
}

return JSON.stringify(results);
},
closeRelatedItems: function() {
var caseId = this.getParameter('sysparm_case_id');

// Close child cases
var childCases = new GlideRecord('sn_hr_core_case');
childCases.addQuery('parent', caseId);
childCases.query();
while (childCases.next()) {
childCases.setValue('state', '3');
childCases.update();
}

// Close tasks
var tasks = new GlideRecord('sn_hr_core_task');
tasks.addQuery('hr_case', caseId);
tasks.query();
while (tasks.next()) {
tasks.setValue('state', '3');
tasks.update();
}

return "done";

},
type: 'close_task'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
}
}
});
}
Loading