- 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-20-2015 02:08 PM
Almost there! Does this line look right? It is still returning null.
- return cat_item.category.name; // or return the sys_id
- 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-20-2015 02:25 PM
SUCCESS!! Thank you so much!
For anyone ever looking back, here is the final code:
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:
var getCategoryFromCatalogItem = Class.create();
getCategoryFromCatalogItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCategory: function() {
var cat_item = new GlideRecord('sc_cat_item');
var sysID = this.getParameter('sysparm_sysid');
if(cat_item.get(sysID)){
return cat_item.category.title; // or return the sys_id
}
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 02:41 PM
This examples may help. There is a an example of a callback function and client-side gliderecord.
Client Script Examples — ServiceNow ELITE.com
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 02:47 PM
However, client side glide record calls are not best practice.
Other methods, GlideRecord and g_form.getReference() are also available for retrieving server information. However, these methods are no longer recommended due to their performance impact. Both methods retrieve all fields in the requested GlideRecord when most cases only require one field.
source: http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#Minimize_Server_Lookups