Can I run multiple catalogue client script on one Variable in Record Producer ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 03:22 AM
Hii
I have one record producer in which there is a variable called account which is a Reference field.
on 'account 'change there is Catalogue onChange script called 'X' with ordering 200.
I have created anther onchange Catalogue script called 'Y" with ordering 400 on 'account' filed .
so problem is whenever I am changing filed 'account ' filed 'Y' script is executing first instead of 'X' .
So what should I do ? how can I control 'X' script executng first
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 05:59 AM
Hi Jay,
What you describe of your setup should work the way you need. Order of execution is a well established function in ServiceNow. I have found that in most cases it is simpler to have one rule for On Change of a given field. It simplifies things since you need to specify the criteria for the scripted actions in the script.
Have you embedded messages (g_form.addInfoMessage())in each of the scripts that tell you when each script is firing?
Is it possible that what is actually happening is that script X is firing but not needing to do anything and that Y fires making a change that gets picked up by X?
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 08:55 AM
In ServiceNow, the execution order of onChange Catalogue scripts is determined by the ordering field on the script record. A lower number in the ordering field indicates that the script should be executed earlier than scripts with higher numbers.
In your case, you have set the ordering of script 'X' to 200 and the ordering of script 'Y' to 400. This means that script 'Y' will be executed before script 'X' when the 'account' field is changed.
To make sure that script 'X' is executed before script 'Y', you need to change the ordering field of script 'Y' to a number higher than 200. For example, you could set the ordering of script 'Y' to 300 or any number greater than 200 but less than 400.
To do this, you can navigate to the 'Y' script record in the ServiceNow instance and update the ordering field to the desired value. Once you have done this, save the record and test the 'account' field change again. Script 'X' should now be executed before script 'Y' when the 'account' field is changed.
Please mark my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2023 09:09 AM
Hi @jay97 ,
The Best Solution for this will be to create single client script.
Example:
Add Conditional Statement
if(Value == X){
function1();
}
else if(Value == Y){
function2();
}
function1 (){
Add your logic here for value X
}
function2 (){
Add your logic here for value Y
}