How to set string field value based on choice field type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 09:52 PM
Hi,
Field 1(Issue) Choice Field: Mobile Issue, CPU Issue.
Field 2: based on choice selection in filed 1, fields 2 value should populate.
EX: in Field 1 I have selected Mobile Issue, in Field 2 it should populate "Describe the issue"
in Field 1 I have selected CPU Issue, in Field 2 it should populate "CPU not working".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:02 PM
You can use Onchange Client Script on field 1.
onchange client script:-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:02 PM - edited 02-13-2023 10:04 PM
Hi @sriram7
You can write onchange client script with below logic
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue == 'Mobile Issue') //map proper value here.
g_form.setValue('field_name', 'Describe the issue'); //map proper field here.
else if (newValue == 'CPU Issue') //map proper value here.
g_form.setValue('field_name', 'Describe the issue'); //map proper field here.
else
g_form.setValue('field_name', ''); //map proper field here.
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:06 PM
Hi Ram,
To set the value of a string field based on the value of a choice field in ServiceNow, you can use a client script
var choiceValue = g_form.getValue('Issue');
// Set the value of the string field based on the value of the choice field
if (choiceValue == 'Mobile Issue')
{
g_form.setValue('string_field', 'Field1');
}
else if (choiceValue == ' CPU Issue')
{
g_form.setValue('string_field', 'Field 2');
}
else
{
g_form.setValue('string_field', '');
}
You can modify based on your requirement .
Please mark helpful or correct if its helping
Thank you
Vijay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:12 PM
Hello Sriram,
Please find the below logic.
onchange of field 1
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var issues=g_form.getValue('field_1');
if (issues == 'Mobile Issue')
g_form.setVisible('field_2', true);
else if (issues == 'CPU Issue')
g_form.setVisible('field_2', true);
}