- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 06:13 AM - edited 02-26-2023 11:10 PM
Hi Developers,
I'm trying to build a new Catalog Item for Minor changes required on existing Catalog Item on the system.
I just have rough design in my mind & I was wondering,
How can I create a variable in New Item, Which will show all variable of the selected Catalog Item that user wants to modify.
Ex:- Below I have selected "Naveen Learning" Catalog Item.
Now I want to create a new variable below this ("Select Catalog Item") which will show all available variable under this Item. So user can select for modification.
I tried to create a variable referencing to item_option_new table but this show all the variables available in the system. I need to show only which are related to above selected Catalog Item.
Please suggest.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 01:06 AM
variables can be directly linked to catalog item or they can be part of some variable set
so use this; you need to use script include for this
javascript:'cat_item='+ current.variables.choose_variable_from_the_catalog + '^ORsys_idIN' + fetchVariables(current.variables.choose_variable_from_the_catalog);
function fetchVariables(itemSysId){
var arr = [];
var gr = new GlideRecord("io_set_item");
gr.addQuery("sc_cat_item", itemSysId);
gr.query();
while(gr.next()) {
var rec = new GlideRecord('item_option_new');
rec.addQuery('variable_set', gr.variable_set);
rec.query();
while(rec.next()){
arr.push(rec.getUniqueValue());
}
}
return arr.toString();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 12:09 AM
Thank you. That works.
But it's not fetching variables from Variable set attached to specific Item.
Any suggestion for this plz?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 01:06 AM
variables can be directly linked to catalog item or they can be part of some variable set
so use this; you need to use script include for this
javascript:'cat_item='+ current.variables.choose_variable_from_the_catalog + '^ORsys_idIN' + fetchVariables(current.variables.choose_variable_from_the_catalog);
function fetchVariables(itemSysId){
var arr = [];
var gr = new GlideRecord("io_set_item");
gr.addQuery("sc_cat_item", itemSysId);
gr.query();
while(gr.next()) {
var rec = new GlideRecord('item_option_new');
rec.addQuery('variable_set', gr.variable_set);
rec.query();
while(rec.next()){
arr.push(rec.getUniqueValue());
}
}
return arr.toString();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 02:27 AM
I tried this but no luck.
Choose variable from catalog item is showing all variables from the variable table.
It's not specifically showing variables & variable set from Item called "Naveen Learning" from variable called Select Catalog Item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 02:29 AM
did you debug by adding gs.info() in the script include function?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 10:45 PM
Yes.
This is working now,
I had to change values on variable.
Also, I realized, If end user is allowed to modify variable from variable set.
This will impact all the Item to which variable set is included In.
Not a good practice.
Do you suggest something?