How can I autopopulate configuration item based on category and subcategory on the incident form?

Ria
Tera Contributor
 
3 REPLIES 3

Community Alums
Not applicable

Hello @Ria ,

 

If there is a relationship between cmdb_ci and the incident categories, this can be done. I don't believe the cmdb_ci categories correspond to the incident categories. 

 

1. Use client callable script include to look up a Configuration Item (CI) based on category and subcategory and return the CI sys_id.

 

Client Callable Script Include:


var CILookup = Class.create();
CILookup.prototype = {
initialize: function () {},
getCI: function (category, subcategory) {
var ciGr = new GlideRecord('cmdb_ci');
ciGr.addQuery('category', category);
ciGr.addQuery('subcategory', subcategory);
ciGr.query();
if (ciGr.next()) {
ciSysId = ciGr.getValue('sys_id');
}

return ciSysId;
},

type: 'CILookup'
};

 

Client Script with GlideAjax:

 

function onChange() {
var category = g_form.getValue('category_field'); 
var subcategory = g_form.getValue('subcategory_field'); 

var ga = new GlideAjax('CILookup'); 
ga.addParam('sysparm_name', 'getCI');
ga.addParam('sysparm_category', category);
ga.addParam('sysparm_subcategory', subcategory);
ga.getXML(function (response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer) {
g_form.setValue('ci_field', answer);
}
});
}

 

OR

 

You can set this with reference qualifiers if you have a relationship:

javascript: 'category=' + current.category.getDisplayValue() +'^subcategory='+current.subcategory.getDisplayValue();

 

And please refer to this also: https://www.servicenow.com/community/itsm-forum/based-on-category-and-subcategory-populate-configura...

 

@RiaPlease mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.

 

Thank You!

Ria
Tera Contributor

Hi Khushboo,

 

We don't have any relationship between cmdb_ci and the incident categories. Is there any other way to achieve this?

 

Thank you!

Community Alums
Not applicable

Hello Riya,

 

If there is no relation, then it will only be possible if you have the same subcategory and category choices in both the cmdb_ci table and the incident table.

Otherwise, you need to hardcode the sys_ids of the CI in the code, but this is not a feasible solution.

 

Thanks!