#ServiceNow.
Many a times we need to fetch data through a particular Reference field on a table, so we either go by dot-walking approach or we do multiple GlideRecords to fetch it. Below is a much more efficient way to do it using “getRefRecord()” method which returns us a GlideRecord object for that particular record referenced in our Reference field.
getRefRecord() should always be followed by isValidRecord() check.
var gr = new GlideRecord(“incident”);
gr.get(“bbfff36b2f232010268ce33df699bGhjk”); //sys_id of the incident record
var caller_object = gr.caller_id.getRefRecord(); // Get a GlideRecord object for the referenced sys_user record
gs.info(caller_object.email); //you can use object to access various fields
gs.info(caller_object.mobile_phone);
It’s useful to fetch the data as well as more useful to update data as that cannot be achieved via dot walk. Below is the example:
Update data of a reference field table without GlideRecord.
var caller = current.caller_id.getRefRecord();
caller.email = ‘[email protected]’;
caller.update();
You can pass this object as a parameter to your other functions as well.
P.S. : If the reference element does not contain a value, it returns an empty GlideRecord object, not a NULL object.
Please feel free to post your thoughts in the comment sections. 😊
Greta article Maroof!but what are impacts of this function?
By using dotwalk you get one field value. Using this method will give you the whole record as an object to use anywhere.
This approach is helpful.
Get the reference object and fetch the data.
Keep it up Maroof.
Very informative, keep it up
It’s useful to fetch the data as well as more useful to update data as that cannot be achieved via dot walk. Below is the example:
Update data of a reference field table without GlideRecord.
var caller = current.caller_id.getRefRecord();
caller.email = ‘[email protected]’;
caller.update();
I consider, that you are right. I am assured. I can prove it.
Thanks for the Information… cheers
In it something is. Thanks for an explanation.