Anything similar to a getDisplayValue in client script?

thenning
Giga Contributor

We're attempting to do a database query from a client script (I know, generally not a good idea). Running into an issue when setting the form fields to the results, its setting the fields to the field value, not the display value. For example in incident, rather than setting the field to "Resolved", its setting it to the value "6".

Wondering if there's anything similar to getDisplayValue() in a client script as there is in a business rule?

5 REPLIES 5

gaidem
ServiceNow Employee
ServiceNow Employee

Please post your script. When setting choice values, you should use the value and not the display value.


thenning
Giga Contributor

Tried a different way to get rid of the database query. Same results using the getReference function.
None of the fields we're trying to set is a choice field, they're all either date/time fields or just string fields.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the page isn't loading
if (!isLoading) {
//If the new value isn't blank
if(newValue != '') {
if (newValue != oldValue) {
var incid = g_form.getReference('u_incident');
g_form.setValue('u_incident_severity', incid.severity);
g_form.setValue('u_incident_state', incid.incident_state);
g_form.setValue('u_short_desc', incid.short_description);
g_form.setValue('u_impacted_business_unit', incid.u_impacted_business_units);
if(g_form.getValue('u_incident_opened') == '') {
g_form.setValue('u_incident_opened', incid.opened_at);
}
if(g_form.getValue('u_incident_resolved') == '') {
g_form.setValue('u_incident_resolved', incid.u_resolved_at);
}
}
}
}
}


gaidem
ServiceNow Employee
ServiceNow Employee

2 things:

This is an onChange script which will only execute on the designated field change.

Have you thrown alert in for debugging? For example:
alert(incid.severity);


Arlen
Mega Expert

Not much documentation exists on this g_form method but it seems to be similar to the server-side getDisplayValue()



g_form.getDisplayBox('field name').value