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
Giga 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

 

 

 

 

 

 

View solution in original post

5 REPLIES 5

Mohith Devatte
Tera Sage

hello @Jagadeesvarraj  i think its because you are not giving any name in the model category query which is why it is taking all the models belonging to all the categories so i am assuming the parameter that you are passing for that function might be  name of the model category 

so directly query models with that parameter

getModels: function(model_category) {
var modelv = [];
var gr_modelcategory1 = new GlideRecord('table1');
gr_modelcategory1.get('name',model_category);
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();


},

Hope this helps 

Mark the answer correct if this helps you 

Thanks

 

anubhavritolia
Giga 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

 

 

 

 

 

 

Thanks for the help, it's working fine now.

Hi @Jagadeesvarraj  

 

Great that it helped you resolve your issue. Feel free to tag me in your posts if you face any issues.