Script include for choice list in UI action - Incident Closure pop up

Danelle Lee
Tera Contributor

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();
});
}
}

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

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

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

2 REPLIES 2

Ahmmed Ali
Mega Sage

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

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Danelle Lee
Tera Contributor

This has worked brilliantly! thank you for your help! 🙂