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

@vinitaraico 

the sysId 1265352c971ce1582519de24a253af88 is found in the direct URL as well

you didn't use the script I shared.

the script I gave uses top.location.href and should work in both native (direct URL) and portal

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

@vinitaraico 

Hope you are doing good.

Did my reply answer your question?

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

Hi Ankur

above solution is not working for now/nav/ui/classic/params/target/com.glideapp.servicecatalog_cat_item_view.do view ,it is only working for serviceportal

 

From maintain item also if you try it above solution will not work