- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 03:02 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 03:08 AM - edited 11-14-2022 03:13 AM
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;
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 03:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 03:08 AM - edited 11-14-2022 03:13 AM
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;
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 05:43 AM
Thanks for the help, it's working fine now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2022 06:04 AM
Great that it helped you resolve your issue. Feel free to tag me in your posts if you face any issues.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023