Unable to populate the choice value in choice type field through onchange ClientScript
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 07:04 AM
On change of field "location" the field "SubCategory" is getting blank, so i need to get the value of "Subcategory" before it get blank and then populate the same value again in the "SubCategory".
But i am able to get the Subcategory choice value as a back end value of choice value with the code:
"var subCat = g_form.getValue('subcategory');"
and when i am trying to populate that choice field back to the sub category field then its not populating it as above code is getting backend value not the lable value
Please suggest how can i populate the same chooice value(lable name) agian to the field
below is the cropped 2 line of code that i am using.
var subCat = g_form.getValue('subcategory');
g_form.setValue('subcategory', subCat);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2022 08:54 PM - edited 12-20-2022 08:56 PM
Hi,
I didn't understand much but give you some refrences:
https://www.servicenow.com/community/developer-forum/g-form-get-label-of-choice/m-p/1729044
note: getDisplayValue() function returns the label name of a choice list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:47 AM
this getDisplayValue() function is not working, as its populating nothing.
I simply wants to get the value which is already selected in the field "Subcategorfy" and then due to some reason it gets blank and i need to populate the same value agian in that field "subcategory"
So there should be 2 line of code 1 line of code should be getting the value which is already there selected for the field, and then another line of code should be setting the same value in that field agin.
please provide me that 2 line of code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 04:37 AM
Hi @VIKAS MISHRA ,
Where are you using these two line of code in your Onchange script? Can you give complete code?
Regards,
Gagan k