logo

NJP

CI Class Manager - Recommended Fields

Import · Sep 03, 2019 · article

The ServiceNow CMDB has a concept of recommended fields (rather than required/mandatory) which are used to assess the health of CIs, but when users are managing their CIs there's no way to know which fields are recommended.

image

This global on load client script will automatically highlight any field that is recommended, making it easy for users to complete.

function onLoad() {

    if(g_form.getTableName().indexOf('cmdb_ci')==0){
        var gr = new GlideRecord('cmdb_recommended_fields');
        gr.addQuery('active','true');
        gr.addQuery('table',g_form.getTableName());
        gr.query(displayResults);
    }

    function displayResults(response){

        response.rows.forEach(function(thisRow){

            thisRow.forEach(function(thisColumn){

                if(thisColumn.name=='recommended'){
                    var thisField = jQuery('input[id="sys_display.'+g_form.getTableName()+'.'+thisColumn.value+'"]').length ==0 ?   jQuery('input[id="'+g_form.getTableName()+'.'+thisColumn.value+'"]'): jQuery('input[id="sys_display.'+g_form.getTableName()+'.'+thisColumn.value+'"]');
                    thisField.css('background','lightyellow');  
                }   
            });
        });
    }
}
View original source

https://www.servicenow.com/community/now-platform-articles/ci-class-manager-recommended-fields/ta-p/2327506