Skip to content
thesnowmonk.com

thesnowmonk.com

Servicenow Tips, Tricks and More.

Menu
  • Home
  • About
  • Contact Us
Menu

How can you convert a GlideRecord Object to a Plain Old JavaScript Object?

Posted on November 11, 2022July 9, 2023 by Arun

In this concise post I am going to show you how to covert a GlideRecord Object into a Plain Old JavaScript Object. The snippet below does just this.

//Following function helps convert a GlideRecord Object to an object
convertGlideRecordToObject: function(gr) {
var recordObj = {};
var fields = gr.getFields();

for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
recordObj[glideElement.getName()] = glideElement.getDisplayValue() + "";
}
}
return recordObj;
};

Now, where could you potentially use this? You could use it while preparing the REST request body, and would need to send a Javascript Object.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About This Site

This site is developed and maintained by a ServiceNow developer just like you! An ardent snowhead who is giving you tried and tested tips, tricks and other snippets to get you ahead of the game.

©2025 thesnowmonk.com | Built using WordPress and Responsive Blogily theme by Superb
Menu
  • Home
  • About
  • Contact Us