Populate list of CI in incident when category is specific one

Manoj10
Tera Contributor

Hello Experts,

Iam trying to achieve to list the particular CI's of class is computer when the category is "BitLocker".

I have written and Script include and Client script to pull the list of it(Given Below)

Im able to achieve through the logs but not in the list of the CI's.

Please help urgently.

 

Script include : 

 

getCI: function() {
var retArray = [];
var relGr = new GlideRecord('cmdb_ci');
//gs.log(CIClass,'YAD');

//if(CIClass=='Bitlocker')
//{
relGr.addQuery('sys_class_name','cmdb_ci_computer');
//}
relGr.query();
while (relGr.next()) {
retArray.push(relGr.sys_id.toString());
}
return 'sys_idIN' + retArray;

},

 

Client script :

OnChange of category :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('category') == 'Bitlocker') {
g_form.clearOptions('cmdb_ci');
var gr = new GlideAjax('CG_ClientUtil');
gr.addParam('sysparm_name', 'getCI'); // function name in script Include
gr.getXML(getCIs);

}
function getCIs(response) {
var CIs = response.responseXML.documentElement.getAttribute("answer");
g_form.addInfoMessage(CIs);
g_form.setValue('cmdb_ci', CIs);

}
}

 

Please help ASAP 

Looping @Ankur Bawiskar 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your question is not clear.

Can you share complete details with screenshots?

if you wish to restrict records then you need to use advanced ref qualifier.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, 

I have similar requirement that in incident form  I need to display list of records based on the category field.

Like when I select category is Application then I need to display affected ci field as cmdb_ci_application table records.

Please help me on this.

Hi @msc ,

 

You can follow the exact same process to which I replied. But change the script include code as below,

 

getCI: function(current)
{
var cat = current.category;
if(cat){
var class_name_string = 'cmdb_ci_' + cat; // This class name concatenation will give the sys_class_name.
//In the case of Application its backend value should be application if not before concatenation use //toLowerCase() function.
//var class_name_string = 'cmdb_ci_' + cat.toLowerCase();
var retArray = [];
var relGr = new GlideRecord('cmdb_ci');
relGr.addQuery('sys_class_name',class_name_string);
relGr.query();
while (relGr.next()) {
retArray.push(relGr.sys_id.toString());
}
return 'sys_idIN' + retArray;
}
else{
return '';
}
},
 
Please mark my answer as helpful and accept it as a solution, if it helps!!

Mallidi Suma
Tera Guru

Hi @Manoj10 ,

 

As per my understanding, you are trying to filter the list of configuration items based on the category field. Since Configuration Item is a Reference Field you need to create an advanced Reference Qualifier.

 

Please find the below steps:-

1. Right-click and go to its dictionary of Configuration Item Field.

2. Go to its Dictionary Override, if there is a Dictionary Override available for your table then use it, else create one for your table(assuming the parent table is Task table of Configuration item in your case).

3. Check the Override Reference qualifier and your script include the name and function like below in the Reference Qualifier field. Script include should not be a client callable.

 

javascript:new TaskUtils().getCI(current); //TaskUtils is the Script Include Name and getCI is the Function name

 

Screenshot 2023-05-23 at 12.34.03 AM.png

 

4. Paste the below code in your script include:-

 

getCI: function(current)
{
if(current.category == 'inquiry')
{
var retArray = [];
var relGr = new GlideRecord('cmdb_ci');
relGr.addQuery('sys_class_name','cmdb_ci_computer');
relGr.query();
while (relGr.next()) {
retArray.push(relGr.sys_id.toString());
}
return 'sys_idIN' + retArray;
}
else
{
return '';
},

 

If you are not using a task extended Configuration item field then go to its Reference Specification -> Use Reference Qualifier ->Reference qual

Paste the below line.

javascript:new TaskUtils().getCI(current); //TaskUtils is the Script Include Name and getCI is the Function name

 

Please mark my answer as helpful and accept it as a solution, if it helps!!