Retrieve a variable's values based on another variable.

Jagadeesvarraj
Tera Contributor

Hii All,

 

I have a requirement here, where there are 2 reference fields, model and model category. when I choose a model category, based on the selected model category, models should appear in model field. 

 

This is the script which I used here, but this script is pushing all the values from the model table even after selecting the model category.

 

getModels: function(model_category) {
var modelv = [];
var gr_modelcategory1 = new GlideRecord('table1');
gr_modelcategory1.get('name','');
var gr_model1 = new GlideRecord('table2');
gr_model1.addQuery('table1', gr_modelcategory1.sys_id);
gr_model1.query();
while (gr_model1.next()) {
modelv.push(gr_model1.sys_id.toString());
}
return "sys_idIN" + modelv.toString();


},

 

but when i keep the specific model category name in this line gr_modelcategory1.get('name',''); as gr_modelcategory1.get('name','PRINTER');. I'm getting the respective models based on the Printer model category. 

 

There are 200+ model categories, and I can't keep the model category names for all of them. 

 

So what should I do here to fetch the models based on the model category. And I'm working this with Advanced reference qualifier, javascript: new Alpha().getModels(current.variables.model_category);

 

Please give your valuable ideas here and Thanks!

1 ACCEPTED SOLUTION

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Jagadeesvarraj  

 

You don't need to do any scripting here.

 

Each model must be linked to particular Model Category. There must be a field on Model table which store "Model Category' say 'Model Category' only.

 

In the Reference qualifiers of Model field, you just have to mentioned below:

 

javascript: 'u_model_category='+ current.variables.model_category;

 

AnubhavRitolia_0-1668424359399.png

 

 

 

 

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

5 REPLIES 5

Sure @AnubhavRitolia Thanks a lot!