- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 05:50 AM
As the subject states, I am trying to work on a client-side script. We have a catalog item that creates a case (sn_customerservice_case) with a predefined case type. I have also added a new choice to custom field choice list labeled u_substate
The requirement: There are several choices in this choice list that overlap between the additional choice lists, However, we are looking to present a new choice as an option for the substate field (custom field) based on this predefined case type, as such I believe we would need an OnLoad client-side script, so once the case loads with the predefined case type the script will run and present the additional choice
I am new to coding and javascript but this is what I have so far, I did something similar for OnChange and it seemed to work but having issues with the OnLoad, it doesn't seem work at all. Any guidance would be much appreciated
function onLoad() {
if (g_form.getValue('u_case_type') == 'services') {
g_form.addOption('u_substate', 'ready_for_triage', 'Ready for Triage');
return;
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 05:44 AM
Animesh,
My original code/logic was working, but after further analysis, there was another Client Script that was running and overwriting my changes. I have since updated the aforementioned client script with my code and its now working as intended.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:17 AM - edited 05-09-2024 06:26 AM
Hi @Gregory Gribben ,
Please try below script
function onLoad() {
if (g_form.getValue('u_case_type') == 'services') {
g_form.addOption('u_substate', 'ready_for_triage', 'Ready for Triage');
}
}
You need to use backend value of the choice. If you want to give multiple addOptions you need to write that multiple times.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:23 AM
When adding an option, you need three values:
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);
the last one, index, is technically optional.
For removing it's: g_form.removeOption(<fieldName>, <choiceValue>);
https://servicenowguru.com/client-scripts-scripting_removing-disabling-choice-list-options/
function onLoad() {
if (g_form.getValue('u_case_type') == 'services') {
g_form.addOption('u_substate', 'ready_for_triage', 'Ready for Triage');
}
}
Please mark my response Correct/Helpful,
Regards,
Siddharam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 06:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 07:04 AM
Hey @Gregory Gribben
Just curious but why are you trying to do this? The case types are technically different tables, you should be able to configure your own choices just by going to Configure Choices on the field. You'll have everything you're inheriting, but you can add your own if you want.