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.