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

Community Alums
Not applicable

I am trying do do the same but with the "element" field on the "sys_journal_field" table. 
@James Roberts have you found a solution?

 

Unfortunately I did not, I instead created a work around, for some specific fields i renamed them completely and others i used a replace.

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())
			{
				// TEST USER'S ABILITY TO SEE WORK_NOTES - IF THEY CAN'T, AND THIS IS A WORK_NOTE, SKIP IT!
				if (rs2.fieldname.getValue().toString() == "work_notes" && !hasItilRole && !isInWorkNotesList)
					continue;                     
				// SKIP BLANK UPDATES - PUT IN PLACE AS CLOSE NOTES UPDATE TO BLANK WHEN INCIDENT REOPENED
				if (rs2.newvalue.toString() == "")
					continue;
				// TIDY UP NAMES AS DISPLAY VALUE STILL SHOWS VALUE OF FIELD NAME WITH UNDERSCORES
				var flvalue;
				if (rs2.fieldname.getDisplayValue() == "reopen_count")
					var flvalue = "incident reopened";
				else
					var flvalue = rs2.fieldname.getDisplayValue().toString().replace("_"," ");

 

I hope this helps a bit.

Community Alums
Not applicable

Thanks for your reply, nice touch. 

I figured out that the issue is with the "Short Field Name" field type because in my case I wanted to use such a field value to test a condition but it never worked.

What actually surprises me is that, contrary to you, I do need to use technical value for my condition and I manage to get the value. However, the script fails to test the "Short Field Name" value.

There is no information about the "Short Field Name" field type online so I just created two different business rules, building my condition with the native condition builder which actually solves my problem.