can you provide script to auto populating category and subcategory based on the CI ?

RMU
Tera Contributor

provide script to auto populating category and subcategory #incident

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@RMU 

you can use onChange client script on CI field and set the values.

but ensure you need to set correct subcategory since subcategory has dependency on category

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @RMU ,

 

Create a onchange client scritp as below:

 

var conItem = g_form.getValue('cmdb_ci');

if (conItem != '' )
{
if(conItem == 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
g_form.setValue('category', 'value');
g_form.setValue('sub_category', 'value');
}else if (conItem == 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
g_form.setValue('category', 'value');
g_form.setValue('sub_category', 'value');
}else if (conItem == 'xxxxxxxxxxxxxxxxxxxxxxxxxx'){
g_form.setValue('category', 'value');
g_form.setValue('sub_category', 'value');
}
}
and so on.........

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Anusha Reddy VK
Mega Guru

Hi @RMU ,

You'll have to write a script to fetch the category and subcategory from the related Configuration Item (CI) and populate the corresponding fields on the Incident form. 

 

Try below code in BR:

 

(function executeRule(current) {
    // Check if Configuration Item (CI) is populated
    if (current.cmdb_ci.nil())
        return;

    // Query Configuration Item to get its category and subcategory
    var ciGR = new GlideRecord('cmdb_ci');
    if (ciGR.get(current.cmdb_ci)) {
        // Populate Category and Subcategory fields on the Incident form
        current.category = ciGR.getValue('category');
        current.subcategory = ciGR.getValue('subcategory');
    }
})(current);

 

If you find my response helpful, please consider selecting "Accept as Solution" and "Helpful" .

 

Thanks,

Anusha