The CreatorCon Call for Content is officially open! Get started here.

Configuration Items based on Category&Sub-Category

samwallace881
Giga Expert

I am trying to limit the Configuration Item list to a specific few that depend on Category and Sub-Category.

When I choose a Category and corresponding Sub-category, In the CI field, I want only certain CIs to be in the drop down.

How can I do this?

I notice that some of my CIs don't even have a Category section when I go to create a new one.

13 REPLIES 13

Hi Sam,



Best way is to use script include as suggested by Micheal making it flexible for any future changes.



Just a small modification in Micheal's code. I feel using array makes it more easier.-


function catsubcat() {


   


      if (current.category == '' || current.subcategory == '') {


              return;


      }


      else {


        var sysIDArray = [];


        var retval = "sys_idIN";


        }


   


      gs.log('both are populated');


      var ci = new GlideRecord ('cmdb_ci');


      ci.addQuery('category', current.category);


      ci.addQuery('subcategory', current.subcategory);


      ci.query();


      while (ci.next()) {


                  sysIDArray.push(ci.sys_id.toString());


              //retval += ci.sys_id + ",";


           


      }


      return retval+sysIDArray.join(',');


}



For more help please check-


Advanced Reference Qualifier Using a Script Include - ServiceNow Guru


Reference Qualifiers - ServiceNow Wiki



Thanks,


Tanaji Patil



--Mark correct/helpful if it helps solving your issue.



is your Question Answered?? please let us know.



i am curious to know are you working on incident Application. if yes, you can use   Ref Qual as "category=current.category^subcategory=current.subcategory^EQ .



simplest way is to use Above code. But i am doubtful about you can limit CI record based on Category and Subcategory.



Thanks & Regards


govind Kumar Sharma


Hi Sam,



Please confirm if your requirement fulfilled .   if no I have few Suggestions for you.



Thanks & Regards


Govind Kumar Sharma


var catsubcat = Class.create();


catsubcat.prototype = {


      initialize: function() {


      },



      type: 'catsubcat'


};



     


      if (current.category == '' || current.subcategory == '') {


             


              return;


        }


     


      else {


             


              var sysIDArray = [];


             


              var retval = "sys_idIN";


             


      }


     


     


     


      gs.log('both are populated');


     


      var ci = new GlideRecord ('cmdb_ci');


     


      ci.addQuery('category', current.category);


     


      ci.addQuery('subcategory', current.subcategory);


     


      ci.query();


     


      while (ci.next()) {


             


              sysIDArray.push(ci.sys_id.toString());


             


              //retval += ci.sys_id + ",";


             


             


             


      }


     


      return retval+sysIDArray.join(',');


     



It gives me an error when I try to make this Script Include.


Maybe I'm typing it in wrong.