- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 02:03 PM
Hello all! I'm pretty new to Service Now so please forgive me if I'm overlooking something.
I'm working on a variable set that is used on about 30 catalog items for cell phone orders. The catalog items reside in different categories for the different carriers available.
I want an HTML variable to display information, depending on the Category the Item is in.
Categories: carriers such as AT&T, Sprint, Verizon, etc.
Items: each of the offerings for that carrier. iPhone, Galaxy, etc.
So if the user is looking at
AT&T > iPhone 5s > hide the HTML variable for the Sprint and Verizon plans and show the AT&T HTML variable
Verizon > Samsung Galaxy > hide the HTML variable for the AT&T and Sprint plans and show the Verizon HTML variable
etc.
I set this up very straight forward with a Catalog UI Policy on the variable set using Reference Field > Catalog Item > Category, however every policy always evaluated as TRUE no matter what. I found on here that UI Policies cannot dot walk, which led me to creating a client script. For the life of me I cannot find a way to evaluate the Category of the Item you are on, from a Client Script of the variable set.
I hope this makes sense and look forward to any advice you may have. Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 02:18 PM
No, it should be:
return cat_item.category.title;
Almost everywhere in ServiceNow it's name, but not on service catalog categories
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 02:24 PM
Hi Brian,
Client side actions, like Client Scripts and UI Policies, are only going to have access to what is present on the form currently. You will need to look into using GlideAjax to pull values from other tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 02:33 PM
Hi Brian,
with g_form.getParameter('sysparm_id') in a client script you can get the sys_id of the catalog item. You can use this to do a GlideAjax call to the server in order to retrieve the category.
glideAjax information on wiki: GlideAjax - ServiceNow Wiki
The script would look something like this:
client script
function onLoad() {
var sysID = g_form.getParameter('sysparm_id');
var ga = new GlideAjax('getCategoryFromCatalogItem') // name of script include
ga.addParam('sysparm_name', 'getCategory'); // name of function in script include
ga.addParam('sysparm_sysid', sysID);
ga.getXML(parseResponse);
function parseResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer")
alert(answer);
}
}
Script include (make sure to set it 'client callable')
var getCategoryFromCatalogItem =Class.create();
getCategoryFromCatalogItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCategory: function() {
var cat_item = new GlideRecord('cat_item');
var sysID = this.getParameter('sysparm_sysid');
if(cat_item.get(sysID)){
return cat_item.category.name; // or return the sys_id
}
},
type: 'getCategoryFromCatalogItem'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 01:29 PM
Thank you for this. I have been working on this script - getting closer to my end goal. I think ultimately it will work, just need to debug.
The if statement in the include is always evaluating as else so it returns null. If I remove that, the return is "undefined".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 01:34 PM
Oops, I see there is a mistake in the script. I'm sorry, please replace
var cat_item = new GlideRecord('cat_item');
with
var cat_item = new GlideRecord('sc_cat_item');
The correct table is the sc_cat_item table for catalog items.