Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you tried gr[fieldName].getLabel();

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark

 

That returns "Field Name" as in the the column name which is Field Name

Ah oke, I misunderstood.

I would think .getDisplayValue() should work fine. I have to test.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Looks to be working fine here 😞

var gr = new GlideRecord('sys_audit');

if(gr.get('a4e16233db0333005c4c9ce8db9619d0')) {
	gs.info(gr.fieldname.getDisplayValue());
}

This gives met the expected choice label instead of the value.

Kind regards,
Mark

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn