Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

What is use of getReference().

niveditakumari
Giga Sage

Hi, 

 

What is use of getReference(). 

Can anyone please give me one example for this. 

 

Regards, 

Nivedita

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Mega Patron

Hi Nivedita,

You can see an example here on the Docs site.

https://docs.servicenow.com/bundle/rome-application-development/page/script/client-scripts/concept/c...

You use it in a client script to retrieve the entire record of a reference field/variable, then you can use another column on the same record in the script to setValue of another field/variable, etc.

Here's an example which sets the value of a location variable to the location that is on the user record of the requested for.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

	var userref = g_form.getReference('requested_for', userLookup);
	  function userLookup(userref){
	    g_form.setValue('location', userref.location.toString());
	  }
}

View solution in original post

5 REPLIES 5

What is the difference between synchronously and asynchronously, in the above context