Advice on Order Guides / Catalog Client Scripts

JennyFlaherty
Kilo Explorer

Hi All

 

I've created an order guide for our New Starter process, and a catalog client script which auto populates the users department, line manager, site and employee id based on the recipients name.   These then cascade onto the ordered items, and performance of filling in the 'Choose Options' is good (we have lots of items which can be selected).

 

I then decided I wanted the same facility when the items are ordered individually via the Service Catalog.   So I set up a second catalog client script, which does exactly the same as order guide client script, but this time based on the UserDetails variable set.   Again, when used via the Service Catalog everything works well.

 

The issue I now have is that since setting up the second client script the 'Order Guide - Choose Options' performance is dreadful.   I assume this is because the variable set client script is running for each of the tabs, even though the details of the fields have already been completed via the cascade.   Is there a way I can set the variable set client script to only run if the fields are not already filled in?

 

Or am I going about this entirely the wrong way?!   Any advice would be much appreciated.   I have attached below screen shots of both my client scripts.

 

Thanks

Jenny

 

1 ACCEPTED SOLUTION

justin_drysdale
Mega Guru

I think your code is fine.   The performance is poor because you are running the script twice on the same objects.   Once on the catalog and again on the variable set. I would pick one and stick with it.   If you are reusing the variable set you can run it from there, otherwise I'd stick to just having the catalog script run.




Also, your performance issues are happening because your onChange is acting as an onLoad as well.   In order to prevent the onChange from running when the page loads, you will need to add an isLoading check.     WITHOUT the check, your code will run once on page load, and again on variable change.   In your case you are having it run twice onLoad, and twice onChange (once from each script).



function onChange(control, oldValue, newValue, isLoading) {


  if (!isLoading) {


          //code that runs when the variable changes, but NOT on page load.


  }


}


View solution in original post

5 REPLIES 5

Mlombardo
Kilo Expert

Hey Jenny,



You should do a getreference with a callback: GlideForm (g form) - ServiceNow Wiki. That should definitely help


JennyFlaherty
Kilo Explorer

Thanks Mlombardo - I'll give that a try!


justin_drysdale
Mega Guru

I think your code is fine.   The performance is poor because you are running the script twice on the same objects.   Once on the catalog and again on the variable set. I would pick one and stick with it.   If you are reusing the variable set you can run it from there, otherwise I'd stick to just having the catalog script run.




Also, your performance issues are happening because your onChange is acting as an onLoad as well.   In order to prevent the onChange from running when the page loads, you will need to add an isLoading check.     WITHOUT the check, your code will run once on page load, and again on variable change.   In your case you are having it run twice onLoad, and twice onChange (once from each script).



function onChange(control, oldValue, newValue, isLoading) {


  if (!isLoading) {


          //code that runs when the variable changes, but NOT on page load.


  }


}


assuming that on an order guide the requested for is read only <so they can't change who it is for on the items>


why not feed the order guide name into the items.. then on each item check the order guide name and   if it is blank skip the script?