Need Help on catalog client script logic is not working for all catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 04:05 AM
Hi Team,
I have a requirement, where on the basis of location change , one question is visible(type -select option) .This question having 7 options,In 2 catalog I wanted to show all 5 option and in other wanted to Hide all 5 option
I tried solution given in below link
http://servicenow.com/community/cmdb-forum/need-help-on-catalog-client-script/m-p/3248701/page/2#
However seems this code is working in some scenario and not working for other catalogs
Below is the on change script on location change
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var url1 = window.location.href;
var url=top.location.href;
//When catalog is search from serviceportal//var url = top.location.href;
//When catalog is search from direct link / var url1=window.location.href
if (url.indexOf('1265352c971ce1582519de24a253af88') > -1 || url.indexOf('55b7b9a0979ce1582519de24a253afc2') > -1)
{
g_form.addOption('deliver_at', 'A');
g_form.addOption('deliver_at', 'B');
g_form.addOption('deliver_at', 'C');
g_form.addOption('deliver_at', 'D');
g_form.addOption('deliver_at', 'E');
g_form.addOption('deliver_at', 'F');
}
else if (url1.indexOf('target/com.glideapp.servicecatalog_cat_item_view')>-1 && url.indexOf('1265352c971ce1582519de24a253af88')>-1 ||url1.indexOf('target/com.glideapp.servicecatalog_cat_item_view')>-1 && url.indexOf('55b7b9a0979ce1582519de24a253afc2')>-1
{
g_form.addOption('deliver_at', 'A');
g_form.addOption('deliver_at', 'B');
g_form.addOption('deliver_at', 'C');
g_form.addOption('deliver_at', 'D');
g_form.addOption('deliver_at', 'E');
g_form.addOption('deliver_at', 'F');
}
else {
g_form.removeOption('deliver_at', 'A');
g_form.removeOption('deliver_at', 'B');
g_form.removeOption('deliver_at', 'C);
g_form.removeOption('deliver_at', 'D');
g_form.removeOption('deliver_at', 'E');
g_form.removeOption('deliver_at', 'F');
}}
UI Type-"All"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 04:15 AM
window object won't work in portal so please use this as this will work in both native and portal and don't check for the native URL explicitly as you will get the sysId of that catalog item anyhow using this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var url = top.location.href; // this will always give you the url
if (url.indexOf('1265352c971ce1582519de24a253af88') > -1 || url.indexOf('55b7b9a0979ce1582519de24a253afc2') > -1) {
g_form.addOption('deliver_at', 'A');
g_form.addOption('deliver_at', 'B');
g_form.addOption('deliver_at', 'C');
g_form.addOption('deliver_at', 'D');
g_form.addOption('deliver_at', 'E');
g_form.addOption('deliver_at', 'F');
} else {
g_form.removeOption('deliver_at', 'A');
g_form.removeOption('deliver_at', 'B');
g_form.removeOption('deliver_at', 'C');
g_form.removeOption('deliver_at', 'D');
g_form.removeOption('deliver_at', 'E');
g_form.removeOption('deliver_at', 'F');
}
}
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
05-01-2025 04:46 AM
Thanks for Quick Help .I tried this However this is working fine when we are doing search from service portal
Like from incident I am submitting advance exchange request to submit a request from a catalog- -There option is Hide for all catalog seems it is not checking if condition
Service portal url- it is working
Direct url not working
https://instance.service-now.com/now/nav/ui/classic/params/target/com.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3D1265352c971ce1582519de24a253af88%26sysparm_link_parent%3Dd258b953c611227a0146101fb1be7c31%26sysparm_catalog%3De0d08b13c3330100c8b837659bba8fb4%26sysparm_catalog_view%3Dcatalog_default%26sysparm_parent_sys_id%3D124dd49287456a506ee6b8cd8bbb35dd%26sysparm_parent_table%3Dincident%26sysparm_view%3Dcatalog_default
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 05:04 AM
so from incident you are clicking a button which is taking user to direct catalog item?
If yes then there also you will find the sysId of catalog item in URL?
Are you not finding that sysId
If my response helped please mark it correct and close the thread so that it benefits future readers.
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
05-01-2025 05:44 AM
yes correct .
For sysid only I have written else if
var url1 = window.location.href;
else if (url1.indexOf('target/com.glideapp.servicecatalog_cat_item_view')>-1 && url.indexOf('1265352c971ce1582519de24a253af88')>-1
||url1.indexOf('target/com.glideapp.servicecatalog_cat_item_view')>-1 && url.indexOf('55b7b9a0979ce1582519de24a253afc2')>-1
can you tell me How to get sysid for bellow url
Direct url not working
https://instance.service-now.com/now/nav/ui/classic/params/target/com.glideapp.servicecatalog_cat_item_view.do%3Fv%3D1%26sysparm_id%3D1265352c971ce1582519de24a253af88%26sysparm_link_parent%3Dd258b953c611227a0146101fb1be7c31%26sysparm_catalog%3De0d08b13c3330100c8b837659bba8fb4%26sysparm_catalog_view%3Dcatalog_default%26sysparm_parent_sys_id%3D124dd49287456a506ee6b8cd8bbb35dd%26sysparm_parent_table%3Dincident%26sysparm_view%3Dcatalog_default