How I made catalog client script onChange across variable set

brian_
Tera Guru

I posted a similar how-to article like this for making UI policies work across variable sets, but how do you make a catalog client script work onChange from a different variable set? Here is how I did it:

Background

Lets start with my use case. I have 2 variable sets applied to a catalog item:

  • User variable set: contains user information, such as who the requested for is, their preferred contact method, etc.
    • This is applied to every catalog item
  • Computer variable set: contains variables to get the computer name for the requested for

I need to populate the computer name variable, inside the computer variable set, when the user changes in the user variable set.

Problem

I could set an onChange catalog client script for the user variable within the User variable set, however that client script will now apply to all catalog items that the User variable set applies to (nearly all catalog items). Since I only want this script to run when the Computer variable set is present, I don't want to do this.

Solution

Now I need to create an onChange catalog client script, for the user variable inside the User variable set, but the catalog client script needs to be applied to the Computer variable set. This is easy to do!

  1. Navigate to the User variable set and create your onChange client script. Go ahead and set the variable it applies to, create your script and verify it works.
  2. Navigate to the Catalog Client Scripts application in your left-side navigator (just type catalog client scripts in the filter at the top). Personalize the list to add the Variable Set column if not already there.
    • personalize script.PNG
  3. Filter down to find the catalog client script you just created in step 1. Double click on the Variable Set column, and change it to your end-result variable set, in this case, the Computer variable set.
    • change var set script.PNG

Why this works

Once the client script is created as onChange and applied to the variable, the variable is saved as a reference to the sys_id. Changing the variable set it applies to, and not changing the variable it runs onChange of, keeps it still watching the origional sys_id.

script.PNG

Downsides

There is a script that runs inside of the catalog client script editor that clears out the variable, when you change the variable set. Therefore, you have to do this method from the list view, or go find and disable that script. I chose the path of least resistance as it didn't require any editing or changes to my instance.

Aside from that, I have not found any other downsides yet. It works flawlessly in both Service Catalog and the new Service Portal in Helsinki. If you know of any, post in a reply!

2 REPLIES 2

urmilla
Kilo Guru

Hi Brian, This is a very helpful post. Works like a charm. Thanks 🙂


hrawat738405662
Tera Contributor

This is really helpful , it worked for me , thanks @brian_