Ho to Get the Text Value of Multiple choice Variable in On Change Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2020 08:56 AM
Hi,
How to Get the Text Value of Multiple choice Variable in On Change Client Script as below
When using the below code in onChange Script
var modelval = g_form.getValue('APAC_EMEA_dell_Laptop');
i am getting the Value "Dell E7390 (Small Laptop)" in modelval
i meed to get text as "Dell Latitude 7300" in modelval .
Please suggest .
Thanks
Venu
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2020 09:12 AM
Hi Venu,
if its not for portal CSJD should be fine. Try with
var fld =g_form.getControl('your field here);
var txt = fld.txt (or it was "value", cant remeber )
Let me know if it is not doing the magic
Cheers,
Joro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2020 09:41 AM
g_form.getValue() will give you the choice value and not label.
The below script worked well for me in Native
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var value = g_form.nameMap;
var parser = JSON.parse(JSON.stringify(value));
var label = '';
for(var i=0;i<parser.length;i++){
if(parser[i].prettyName == newValue){
label = parser[i].label;
break;
}
}
alert(label);
}
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2020 01:29 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2020 09:50 AM
You below Get the label for a choice list value
var choiceLabel = g_form.getOption(<fieldName>, choiceValue).text;
Regards,
Sachin
