Based upon assignment group, category fields to show dynamically

snavuluri
Giga Contributor

Create a category- assignment group mapping table and write client script and script include to handle the show hide if the category, if assignment group is not "software", category and subcategory related to software are not supposed to show up in the incident form.

11 REPLIES 11

Shailesh Bachha
Tera Expert

Hi snavuluri,

You can achieve this also by UI Policy without writing the script

Please refer below (select Incident table)

find_real_file.png

 

Regards,

Shailesh Bachhav

NSB1
Kilo Contributor

Hi,

       How to get the fields of incident category fields to the custom field of u_category [field] and custom table: u_assignment_category .

 

 

Rajesh Chopade
Kilo Expert

Hi snavuluri,

 

I would recommend using UI policy option here.

 

When possible, consider using a UI policy instead of a client script for these reasons:

 

  • UI policies have an Order field to allow full control over the order in which client-side operations take place.
  • UI policies do not require scripting to make a field mandatory, read-only, or visible.

http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#Use_UI_Policies_Instead_of_C...

 

Regards,

Rajesh

NSB1
Kilo Contributor

Hi All,

        Please give solution for the below code. on load or on change the field value of assignment group, the value of the category field to changes automatically which is based upon the mapping table (as below). 

find_real_file.png

find_real_file.png

 

And the code :

Script include:  (Client callable) & for all scope application

var clientscriptprocessing = Class.create();
clientscriptprocessing.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssignmentGroup: function() {
var list = [];
var assignment_group = this.getParameter('sysparm_assignmentgroup');
var gr = new GlideRecord('u_category_assignment_group');
gr.addQuery('u_assignment_group', assignment_group);
gr.query();
while (gr.next()) {
var item_val = gr.getDisplayValue('u_category');
list.push(item_val);
}
return JSON.stringify(list);
},
type: 'clientscriptprocessing'
});

 

Client script: ( Table : incident, Type: onchange & field name: assignment group)

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

// g_form.clearOptions('category');
var cat = g_form.getValue('assignment_group');
var ga = new GlideAjax('clientscriptprocessing');
ga.addParam('sysparm_name', 'getAssignmentGroup');
ga.addParam('sysparm_assignmentgroup', cat); //.toString());
ga.getXML(getAssignmentGroup);

function getAssignmentGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var myObj = JSON.parse(answer);
if (myObj.length > 0) {
for (var i = 0; i < myObj.length; i++) {
g_form.setValue('category', myObj[i].toLowerCase(), myObj[i].toLowerCase());
}
}
}
}

 

 

Here issue is that, when loading / changed the incident record, getting the respective value but it is getting added and show in blue colour to the category field which suppose the select from existing values based upon mapping table and also to show only those respective fields. 

find_real_file.png                  

When i  uncomment the // g_form.clearOptions('category'); in client script, it is getting the value as required but showing in blue colour.  find_real_file.png

So, please give the solution that need to pass backend values instead of frontend values to fetch the properly.

 

 

Hi NSB,

You can use "On Change" client script

My Test case - If assignment group is "Problem Analyzer" then Category will change to "Hardware" automatically and "Sub category" will reflect accordingly

(Note - In script use "sys_id" of required group and backend value of Category)

find_real_file.png

and give dependency of "Sub Category" field on "category" field using configure dictionary.

find_real_file.png

 

Please mark Correct and Helpful if this really works for you.

Regards,

Shailesh Bachhav