- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 06:02 AM
Hi,
I'm trying to script, so that when I choose an option in two different select box variables (Environment and Version), the "target server" variable will have a specific text (for single line text), or maybe set the choice if I use select box.
I have done the following so far:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 06:53 AM
Double check your using the correct field names in your getters and setters. Also add some alerts throughout the code to see where the script is breaking.
I have a feeling this could be the condition which triggers the client script. You want to change the variable name to either environment or version. This way the client script is triggered when one of those is changed, not onChange of the target server field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 09:08 AM
Hi, Dylan.
After I made the complete script, I found that it is only triggering the script when I change the choice selected in what is in the variable name.
What I mean is I have a choice list under Environment (a, b, c, and d). and another set of choices under Version (a,b, c, and d).
I used 'version' for variable name in the onchange script.
When I tested out the record producer, I select from the Environment, and after I select a choice in the Version, the targetserver field results just fine. but if I change my mind and selected a different environment, if wouldn't change the result in the target server - I had to select a different option in the version to take effect.
Is there any additional script I can add to automatically change the targetserver result as soon as I change either the Version or the Environment?
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 09:28 AM
Unfortunately, you can't select multiple fields to trigger a client script, but if anyone else knows of a way to do so, feel free to let us know.
The simplest solution is to create another catalog client script and paste in the same script just triggered onChange of the environment field. Kinda stinks you have to copy and paste code like this, but it's something you just have to do and get's the job done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 09:39 AM
The workaround works!!!
I know ServiceNow lacks something here and there, and perhaps could be taken as future enhancement, but I really don't mind having to copy and paste the codes, so long as they work.
I wish there's a compilation of "tricks"/information like this online, so anyone as green as me can look up as FAQs.
Thanks again, Dylan!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2021 07:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2018 06:51 AM
Hi
You can try addOption/clearOption function here.
Once the end use change the environment and version, you can change the option in target server.
Below is the example :
var dbenvironment = g_form.getValue("db_enviornment");
var dbversion = g_form.getValue("dbversion");
g_form.clearOptions("targetserver");
if(dbenvironment == 'Development' and dbversion == 'SQL Server 2014'){
g_form.addOption(String fieldName, String choiceValue, String choiceLabel)
g_form.addOption("targetserver","DevA","A");
g_form.addOption("targetserver","DevB","B");
}
if(dbenvironment == 'Test' and dbversion == 'SQL Server 2014'){
g_form.addOption("targetserver","testB","B");
}
ifif(dbenvironment == 'Prod' and dbversion == 'SQL Server 2014'){
g_form.addOption("targetserver","prodA","A");}
Let me know if it helps
-Jaya