- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 01:44 PM
I've created a new hire order guide with the several variables I'd like to share across all included catalog items.
Common info I'd like to have on all catalog tasks: Supervisor/First Name/Last Name/Shift/Title/Department/EmployeeID
Catalog items: Build Computer/ Setup Phone/ Setup Email/ Create Access
There is no need for the user to see all those fields listed on each catalog item within the order guide, but I want to pass the variables to help the fulfiller.
and the following set of informaktion I'd like to carry over to each catalog item, but
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 02:11 PM
Hi Ya,
Create the common variables in a variable set and include the variable set on the order guide and all catalog items that can be selected in the order guide. In the variable set you need to create an onload client script with UI Type set to "All" so it runs on both platform and Service Portal. Should look something like this:
function onLoad() {
if (window === null) {
// check if we are in an order guide using the g_service_catalog api for Service Portal and Mobile
var isOrderGuide = g_service_catalog.isOrderGuide();
if (isOrderGuide) {
//call function to hide the fields on the catalog items if this is an order guide.
hideVariables();
}
}
else {
var item = gel("current_item");
var guide = gel("sysparm_guide");
if (item != null && guide != null && item.value != guide.value) {
hideVariables();
}
}
function hideVariables(){
g_form.setDisplay('your_var1',false);
g_form.setMandatory('your_var2',false);
g_form.setDisplay('your_var2',false);
}
}
On the order guide tick "Cascade variables" option which will copy the value of the data captured in the order guide down to the Service Catalogue items
That should now hide the variables, when displayed within an order guide. More information can be found about cascading variables at the following link - Cascade an order guide variable
Let me know how you get along.
Brent
P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2019 01:38 AM
Hi Bent,
I am not sure If am clear with my issue.
I have written the code as below
function onLoad() {
//Type appropriate comment here, and begin script below
if (window === null) {
// check if we are in an order guide using the g_service_catalog api for Service Portal and Mobile
var isOrderGuide = g_service_catalog.isOrderGuide();
if (isOrderGuide) {
//call function to hide the fields on the catalog items if this is an order guide.
hideVariables();
}
}
else {
var item = gel("current_item");
var guide = gel("sysparm_guide");
if (item != null && guide != null && item.value != guide.value && item.value!='372510b11ba3ab80b1ab0dc8cd4bcbdb') {
hideVariables();
}
}
function hideVariables(){
g_form.setDisplay('name',false);
g_form.setDisplay('first_name',false);
g_form.setDisplay('middle_name',false);
g_form.setDisplay('last_name',false);
g_form.setDisplay('division',false);
g_form.setDisplay('country',false);
g_form.setDisplay('location',false);
g_form.setDisplay('manager',false);
g_form.setDisplay('title',false);
g_form.setDisplay('termination',false);
}
}
I have included the variable set in each catalog item and it is hidden now with this script when the catalog items are included in order guide.
But if i want to submit a single catalog item (not from the order guide), the variables are not getting hidden
I even want the variable set to be hidden if only single catalog item is used for submitting the request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2019 11:19 AM
You've added an additional test on the item value. I think this is causing the problem. Try the following;
if (item != null && guide != null && item.value != guide.value && (guide != null && item.value !='372510b11ba3ab80b1ab0dc8cd4bcbdb')) {
Letme know if it works for you.
Brent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 08:02 AM
Brent,
The variable set is helping me greatly, but all the variable set fields are still appearing on the order guide in each catalog item tab. Is there anyway to get them to pass through without listing them on each catalog item?
Thanks,
Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 12:35 PM
Brent,
This worked like a champ. I did however have to change:
var item = gel("current_item");
var guide = gel("sysparm_guide");
to
var item = g_form.getControl('current_item');
var guide = g_form.getControl('sysparm_guide');
I check all "Applies" items. See screenshot. Can you see an reason this will cause an issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 05:12 PM
Hi Jeremy,
The script only needs to be applied to "Applies on a Catalog Item view". You don't need to apply it at RITM, Task or Target record. I haven't seen any errors on our Kingston instance relating to the use of gel?
The use of "gel" or "$" (DOM manipulation) is the only way (I am aware of) to extract the item and guide sys_id's on the platform interface side. We normally steer away from DOM manipulation as it is prone to breaking between upgrades. However, according to the London release ServiceNow docs, this is still the preferred method for the cascading variables use case - Hide cascaded variables
If anyone can give me an alternative then I'd love to know. I posted a question on the community about year ago as I was looking for an alternative to gel or $ then.
Glad you got it working.
Brent
P.S. If my suggestion helped then please mark as helpful and/or correct so other community members can benefit from this information.