- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 09:05 PM
Hi,
Just wondering if anyone might be able to assist here? Trying to add a pop up window on closure on an incident so that if someone forgets to complete the resolution fields it will display in a pop up window.
I have configured this on the 'resolve' UI Action of Agent workspace using a client script and a script include however the pop up window displays all the categories. I would like it to show the closure categories dependent on the subcategory selected on the incident. Is there any way to achieve this?
Script Include:
var getChoicesAJAX = Class.create();
getChoicesAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getChoices: function() {
var elementsparm = String(this.getParameter('sysparm_elements'));
// var elementsparm = ('dependent_value',this.getParameter('sysparm_elements')); //tried adding 'dependent_value' but this didnt filter the list'
var elements = elementsparm.split(",");
var table = this.getParameter('sysparm_table');
choicesObj = {};
for (var i = 0; i < elements.length; i++) {
var choiceRecord = new GlideRecord('sys_choice');
choiceRecord.addEncodedQuery('name=' + table + '^element=' + elements[i] + '^inactive=false');
choiceRecord.query();
choiceRecord.setLimit(30);
var name = elements[i];
choicesObj[name] = {};
var count = 0;
while (choiceRecord.next()) {
choicesObj[name][count] = {
displayValue: choiceRecord.label.toString(),
value: choiceRecord.value.toString()
};
count++;
}
}
var result = JSON.stringify(choicesObj);
return result;
},
type: 'getChoicesAJAX'
});
Client script on UI Action:
var gA = new GlideAjax("getChoicesAJAX");
gA.addParam('sysparm_elements', 'u_sub_sub_category'); // this is the name of the closure category field
gA.addParam('sysparm_table', 'incident');
gA.addParam('sysparm_name', 'getChoices');
gA.getXML(getChoices);
function getChoices(response) {
choicesObj = {};
var answer = response.responseXML.documentElement.getAttribute("answer");
choicesObj = JSON.parse(answer);
closeCodeChoices = [];
for (var key in choicesObj.u_sub_sub_category) {
if (choicesObj.u_sub_sub_category.hasOwnProperty(key)) {
var closeCodeSet = {
displayValue: choicesObj.u_sub_sub_category[key].displayValue,
value: choicesObj.u_sub_sub_category[key].value
};
closeCodeChoices.push(closeCodeSet);
}
}
var fields = [
{
type: 'choice',
name: 'closure_category',
label: getMessage('Closure Category'),
value: g_form.getValue('u_sub_sub_category'),
displayValue: g_form.getDisplayValue('u_sub_sub_category'),
choices: closeCodeChoices,
mandatory: true
},
{
type: 'textarea',
name: 'closure_notes',
label: getMessage('Closure Notes'),
mandatory: true
},
];
g_modal.showFields({
title: "Please provide a closure reason",
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_form.setValue('u_sub_sub_category', fieldValues.updatedFields[0].value);
g_form.setValue('close_notes', fieldValues.updatedFields[1].value);
g_form.save();
g_form.submit(g_form.getActionName());
g_aw.closeRecord();
});
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 09:58 PM
Hello,
You need to pass current subcategory value in GlideAjax and in script include, add query to get choice values for current subcategory only.
In Client script, add one more parameter in GlideAjax script as
var gA = new GlideAjax("getChoicesAJAX");
gA.addParam('sysparm_elements', 'u_sub_sub_category'); // this is the name of the closure category field
gA.addParam('sysparm_table', 'incident');
gA.addParam('sysparm_name', 'getChoices');
gA.addParam('sysparm_subcategory', g_form.getValue("subcategory")); //verify field name for subcategory
gA.getXML(getChoices);
In script include, add query as below:
var choiceRecord = new GlideRecord('sys_choice');
choiceRecord.addEncodedQuery('name=' + table + '^element=' + elements[i] + '^inactive=false');
choiceRecord.addQuery("dependent_value",this.getParameter("sysparm_subcategory"));
choiceRecord.query();
Thank you,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2022 09:58 PM
Hello,
You need to pass current subcategory value in GlideAjax and in script include, add query to get choice values for current subcategory only.
In Client script, add one more parameter in GlideAjax script as
var gA = new GlideAjax("getChoicesAJAX");
gA.addParam('sysparm_elements', 'u_sub_sub_category'); // this is the name of the closure category field
gA.addParam('sysparm_table', 'incident');
gA.addParam('sysparm_name', 'getChoices');
gA.addParam('sysparm_subcategory', g_form.getValue("subcategory")); //verify field name for subcategory
gA.getXML(getChoices);
In script include, add query as below:
var choiceRecord = new GlideRecord('sys_choice');
choiceRecord.addEncodedQuery('name=' + table + '^element=' + elements[i] + '^inactive=false');
choiceRecord.addQuery("dependent_value",this.getParameter("sysparm_subcategory"));
choiceRecord.query();
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 12:11 AM
This has worked brilliantly! thank you for your help! 🙂