Scoped application alternative to GlideRecordXMLSerializer()

ryanlitwiller
Giga Guru

Looking for an alternative to GlideRecordXMLSerializer() for a scoped application. Looking to get the entire XML of the glide record.

1 ACCEPTED SOLUTION

Brian Scott2
Tera Expert

Try this;

 

Create a script include under the global application that is accessible from all application scopes and paste this in as the script.

 

var ScopedXmlSerializer = Class.create();
ScopedXmlSerializer.prototype = {
initialize: function() {
},
serialize:function(currentRecord)
{
var xmlSerializer = new GlideRecordXMLSerializer();
return xmlSerializer.serialize(currentRecord);
},
type: 'ScopedXmlSerializer'
};

 

I tested in a background script and selected run script in scope <some scope that isn't global> with the following:

var current = new GlideRecord("sys_user");
current.setLimit(1);
current.query();
current.next();

var xml = new global.ScopedXmlSerializer();
var xmlString = xml.serialize(current);
gs.info(xmlString.toString());

View solution in original post

5 REPLIES 5

sachin_namjoshi
Kilo Patron
Kilo Patron

You can use

 

 

 

var json = new global.JSON().encode(object);

 

 

to encode object to JSON.

 

Please check below blog for additional details

 

https://community.servicenow.com/community?id=community_blog&sys_id=235e2eaddbd0dbc01dcaf3231f961929

 

Regards,

Sachin

The problem is I don't have an object I have a glide record and I'm looking to get all the xml for that record to pass to another application (external web service).

This GQL solution seem like a lot of overhead, do you have any additional details about this solution?

Why don't you glide the record and get all required field data for sending to external WSDL?

 

Regards,

Sachin

Brian Scott2
Tera Expert

Try this;

 

Create a script include under the global application that is accessible from all application scopes and paste this in as the script.

 

var ScopedXmlSerializer = Class.create();
ScopedXmlSerializer.prototype = {
initialize: function() {
},
serialize:function(currentRecord)
{
var xmlSerializer = new GlideRecordXMLSerializer();
return xmlSerializer.serialize(currentRecord);
},
type: 'ScopedXmlSerializer'
};

 

I tested in a background script and selected run script in scope <some scope that isn't global> with the following:

var current = new GlideRecord("sys_user");
current.setLimit(1);
current.query();
current.next();

var xml = new global.ScopedXmlSerializer();
var xmlString = xml.serialize(current);
gs.info(xmlString.toString());