Need Help on Catalog client script

vinitaraico
Tera Contributor

Hi Team,

 

There is one  variable A-  type -select box in the catalog .This select box  have option 1,option2,otions3,option4. This Catalog variable is part of variable set and variable set is configure in multiple catalog ,Now I have added 2 more option in this variable A

Now my requirement is  the newly added options should be visible only in 2 catalog ,How I can achieve this using client script

 

 

 

 

1 ACCEPTED SOLUTION

@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

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@vinitaraico 

simply use onLoad catalog client script which Applies to your Variable set

Then search in URL the 2 catalog item sysIds

If it's present then show those options

If not then remove those 2 options

function onLoad() {
    var url = top.location.href;
    if (url.indexOf('catalogItemSysId1') > -1 || url.indexOf('catalogItemSysId2') > -1) {
        // show and don't do anything
    } else {
        g_form.removeOptions('variableA', 'choiceValue1');
        g_form.removeOptions('variableA', 'choiceValue2');
    }
}

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,

Thankyou for the reply ,You suggestion helped ,in my case variable A is depend on location hence i have written a on change script

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var url = top.location.href;
   if (url.indexOf('1234562519de24a253af88') > -1 || url.indexOf('784356e1582519de24a253afc2') > -1)
   {
   g_form.addOption('deliver_at', 'ABC05L');
   g_form.addOption('deliver_at', 'ABC105L');
    
}
else{
 g_form.removeOption('deliver_at', 'ABC05L');
   g_form.removeOption('deliver_at', 'ABC105L');
 

}}

 

 

 

 

 

@vinitaraico 

if that variable is shown based on some other variable then ensure you write that in the correct onChange catalog client script/

You never told this in your original question.

The script I shared will work fine as per your original question, you can always enhance it.

I believe I have answered and given a logic on how it can be done.

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