logo

NJP

Export a record in XML and attach it to the record

Import · Jul 26, 2022 · article

You can use following code to export a record as an XML for the backup and attach it to a record. The same XML can be import back to the table using import xml functionality.

attachXML('incident', '217237d5ff30dd10ac0aecaf435b5ef0'); //Pass table name and record sysid

function attachXML(table, record_id) {

var xmlString = "<" + table + ">";

var gd = new GlideRecord(table); gd.get(record_id); for (var key in gd) {

xmlString += "<" + key + ">" + gd[key] + "</" + key + ">";

} xmlString += "</" + table + ">"; var StringUtil = Packages.com.glide.util.StringUtil; var gr = new GlideRecord('ecc_queue'); gr.initialize(); gr.agent = 'AttachmentCreator'; gr.topic = 'AttachmentCreator'; gr.name = 'testing.xml:text/xml'; //update table name & sys_id as needed gr.source = table + ':' + record_id; gr.queue = 'input'; gr.state = 'ready'; gr.payload = StringUtil.base64Encode(xmlString); gr.insert();

}

image

View original source

https://www.servicenow.com/community/now-platform-articles/export-a-record-in-xml-and-attach-it-to-the-record/ta-p/2312637