
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 07-25-2022 10:54 PM
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 = "<xml><" + table + ">";
var gd = new GlideRecord(table);
gd.get(record_id);
for (var key in gd) {
xmlString += "<" + key + ">" + gd[key] + "</" + key + ">";
}
xmlString += "</" + table + "></xml>";
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();
}
- 2,131 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Vandna, This doesn't seem to work. When I try to Import XML it gives me the following error:
File testing.xml is not valid XML and has been deleted

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Kottam,
Please add the generated xml here. I will check the format.
Thanks,
Vandna Ahirwar
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Kottam,
You may need to check the file format, it needs to be saved as UTF-8 (no BOM).
Cheers
Eugene