Need Help on catalog client script logic is not working for all catalog

vinitaraico
Tera Contributor

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;   

https://instance.service-now.com/serviceportal?id=sc_cat_item&sys_id=1265352c971ce1582519de24a253af8...

 

//When catalog is search from direct link / var url1=window.location.href

//https://instance.service-now.com/now/nav/ui/classic/params/target/com.glideapp.servicecatalog_cat_it...

 


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"

Isolate script
 
Seems like for some catalog it is working for some all options are visible ,However I want these options in this 2 catalog which sysid is mention in script
 

 

 

 

 

 

 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@vinitaraico 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

https://instance.service-now.com/serviceportal?id=sc_cat_item&sys_id=0f8a71ec97dce1582519de24a253af9...

 

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

 

 

 

@vinitaraico 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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