getvalue of Short Field Name

James Roberts
Giga Contributor

I am trying to get value form "Field Name" on one of the audit tables.

these Field Name fields have a type of short field name.

var rs2 = new GlideRecord("sys_audit");
			rs2.addQuery("documentkey", data.sys_id.toString());
			rs2.addQuery("tablename", data.table.toString());
			rs2.addQuery("fieldname", "IN", fieldTypes.join(","));
			rs2.orderByDesc("sys_created_on");
			rs2.query();
			while (rs2.next())
			{

			var fl = rs2.fieldname.getDisplayValue();

both getvalue and getdisplay value are returning the system name rather than the friendly name.

What I mean by this is, it is returning "reopened_by" instead of "Last Reopened By"

find_real_file.png

find_real_file.png

Any idea how I get the latter?

12 REPLIES 12

For some reason gr.fieldname.getDisplayValue() gives me still the technical name and not the Display Value. Any idea why?

Lukasz Bojara
Kilo Sage

Hi,

The getValue() and getDisplayValue() will not give you the field label but the value itself so e.g. if this a reference to sys_user table than getValue() will give you sys_id of the user and getDisplayValue() will give you full name. You should use the getLabel() method:

gr.number.getLabel(); // replace number with your column name

 

Hope this helped.

 

Best regards,
Łukasz

James Roberts
Giga Contributor

I think i may of not made it entirely clear

In the sys_audit table the is a field/column called "Field Name" which has a value in the example of "reopened_by"

find_real_file.png

however if you click into that record their is a drop field called "Field Name" with a currently selected value of "Last reopened by"

 find_real_file.png

What i want returned is this value, i want the "Last reopened by"

 

This is the same field (as far as i can tell) but it has two different display values and i'm not sure how to get this second value?!

find_real_file.png

Edgardo Amaya1
Kilo Contributor

If I understand you, what you want is to return the value of the "field" saved in the "field_name" field, so ....

DOC info

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_ScopedGlideRecordGetValue_String

var gr = new GlideRecord('incident');
gr.orderBy('number');
gr.query('active','true');
gr.next();
gs.info(gr.getValue('number')); <---- get info about 'number' field

 

in your case you need to do someting like this...

 var fl = rs2.info(rs2.getValue('fieldname'));

please try and tell me how it turned out.

I might be using it wrong but it does not seem to work. I don't appear to be getting any value using this.