How do we set the category and sub category based on CI

Tharun13
Tera Contributor

Hi All,

Incident created from third party with CI.

We have multiple Configuration item(reference cmdb_ci table) with category and subcategory.

how to set the category and sub category based on CI.

 

Regards,

Tharun

4 REPLIES 4

Namrata Ghorpad
Mega Sage
Mega Sage

Hello Tharun,

Configure the Dictionary for Category and Subcategory field and in that set the Configuration Item as a Dependent field.

 

Please mark my answer as helpful/correct if it helps you.

Thanks,

Namrata

SumanthDosapati
Mega Sage
Mega Sage

Hi Tharun,

As suggested by Namrata, you can use dependent field in dictionary level.

Or else if list is big, you can use an on Change client script

 

Regards,
Sumanth

Feel free to reach out if you have further questions or else you can mark appropriate answer as correct and helpful to close the thread so that it benefits future visitors also.

Regards,
Sumanth

Saroj Patel1
Tera Contributor

 

// Remove dependency between company and configuration item and create onchange client script for configuration item field




function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }
    var category = Array.from(g_form.getElement('category')).map(function(item) {
        return item.text;
    });
    var ci = g_form.getReference('cmdb_ci', setRelatedValue);

    function setRelatedValue(cmdbCI) {
        var ciCompany = cmdbCI.company || '';
        var ciCategory = cmdbCI.category || '';
        var ciSubcategory = cmdbCI.subcategory || '';
		
		g_form.setValue('company', ciCompany);
        g_form.setReadOnly('company', Boolean(ciCompany));

        if (category.includes(ciCategory)) {
            g_form.setValue('category', ciCategory);
            setTimeout(function() {
                var subcategory = Array.from(g_form.getElement('subcategory')).map(function(item) {
                    return item.text;
                });
                if (subcategory.includes(ciSubcategory))
                    g_form.setValue('subcategory', ciSubcategory);
            }, 1000);

        }

    }​