The CreatorCon Call for Content is officially open! Get started here.

Client Script: DisplayValue of a field

palmen
Tera Guru

I'm having issues to get the display values of two fields in a client script.

g_form.getDisplayValue('field_name') will return the number of the incident and not the actual display value of the field.

The fields I need the display values for is State (state) and Configuration Item (cmdb_ci).

From what I read in other threads you should use

g_form.getDisplayBox('field_name').value;

When I try this I get an error instead on the form when the Client Script is triggered

find_real_file.png

The code I'm using in the onChange client script is the following

var state = g_form.getDisplayBox('state').value;

alert(state);

The alert won't show, only the above error is displayed.

Any ideas what I could do to get the Display Value of the state field?

1 ACCEPTED SOLUTION

mazhar4
Giga Expert

Did you try this?



var u_stateValue = g_form.getValue('state');


var u_stateLabel = g_form.getOption('state',u_stateValue).text;



PS - Please mark Helpful, Like, or Correct Answer if applicable.


View solution in original post

15 REPLIES 15

Yes, you are right .. its not working for choice list. Its working fine for string field as well.


Time to make a GlideAjax call to get the display value.



There's a good example in the GlideAjax article.



Reference:


Client Scripts - ServiceNow Wiki


GlideAjax - ServiceNow Wiki


Client Script Best Practices - ServiceNow Wiki  


Booth fields are on the form, I've just double checked it.


The state field is only visible on the Admin tab though (only visible to users with role admin)


mazhar4
Giga Expert

Did you try this?



var u_stateValue = g_form.getValue('state');


var u_stateLabel = g_form.getOption('state',u_stateValue).text;



PS - Please mark Helpful, Like, or Correct Answer if applicable.


WINNER! That's the one. I just verified it works.



(Now you know why I shy away from client scripts.)