Catalog Client Scripts, are they limted to variable set?

tahnalos
Kilo Sage

I have two variable sets.  One has variables A and B, and the other has variables C and D.

If I want to set variables C and D from data captured in variables A and B, would a catalog client script that is on the variable set for C and D have access to A and B on the different set?
Or does A, B, C, and D have to be part of the same variable set?

 

4 REPLIES 4

Minh Huy Lam Qu
Giga Sage

Hi there,

 

I create an example based on your question:

There are 2 variable set "Variale Set A" and "Variable Set B"

MinhHuyLamQu_0-1689630048657.png

 

In the varible set A contain variable (var_a), for the variable set B (var_b).

MinhHuyLamQu_1-1689630101613.png

The variable inside these variable set can be access to each other, if you create a catalog client script.

MinhHuyLamQu_2-1689630186042.png

I've create on onChange Catalog Client Script to copy the value of B and set it to A (in the Variable name field you've to choose the Variable Set that need to be capture to another one).

MinhHuyLamQu_3-1689630233258.png

Please try this approach, put some alert if you need to see the value of the field.

Regards,

Huy Lam

Thanks for your help, just one problem: I want the variable set B to populate data from A when A is changed.

The onChange client script only assumes if B is changed.  The logic I need is that when A is changed, B is populated with data from A. 
However, because I do not own Variable Set A (I am not allowed to modify that update set to add my catalog script), the client script must be run from Variable Set B.  Can this be done?

Ankur Bawiskar
Tera Patron
Tera Patron

@tahnalos 

if you want to do some processing on C OR D when A or B changes then 2 ways

1) create onChange catalog client script which Applies to your Catalog Item and select the type as onChange and select the variable A or B

OR

2) create onChange catalog client script which Applies to your variable set and select the correct variable

Since you told you don't own the variable set then you better go with option 1 as the script will run only for your catalog item

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

jMarshal
Mega Sage
Mega Sage

I'm quite sure you can't do this oob. Catalog Client Scripts that are within a variable set are limited to the scope of that variable set. You may be able to get around this with an advanced ajax glide script from within the variable set's Catalog Client Script...but you'll be relying on data that already exists on the server (ajax doesn't work with client session data).