Client OnChange Script - Get Display Value for OldValue

litchick10
Tera Guru

When a reference field (sys_user) is changed, the request is to enter work notes with old value and new value

I cannot seem to figure out how to use the oldvalue (sys_id) to query the Sys_User table

Here is what I have that isn't working- no alert appears

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	var gr = new GlideRecord('sys_user');
	gr.addQuery('name', oldValue);
	gr.query(myCallbackFunction); //Execute the query with callback function

//After the server returns the query recordset, continue here
function myCallbackFunction(gr){
   while (gr.next()) { //While the recordset contains records, iterate through them
      alert(gr.user_name);
   }
}
//HAVE NOT YET UPDATED
		g_form.setValue('work_notes', "Financial Approver changed from " + oldValue +  " to " + newValue);
}
1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

1) Why you want to do this using script. Just add the field in activity log same as state field using funnel icon. Which will show you value transition from old to new.

find_real_file.png

 

2) You have to write a script include and pass the oldValue sys_id there to get name.


Thanks,
Ashutosh 

View solution in original post

1 REPLY 1

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

1) Why you want to do this using script. Just add the field in activity log same as state field using funnel icon. Which will show you value transition from old to new.

find_real_file.png

 

2) You have to write a script include and pass the oldValue sys_id there to get name.


Thanks,
Ashutosh