vandna
Tera Guru

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();
}

Comments
kottam
Tera Contributor

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

vandna
Tera Guru

Hi Kottam,

 

Please add the generated xml here. I will check the format.

 

Thanks,

Vandna Ahirwar

Eugene Severi
Tera Contributor

Hi Kottam,

 

 

You may need to check the file format, it needs to be saved as UTF-8 (no BOM).

 

Cheers

 

Eugene

Version history
Last update:
‎07-25-2022 10:54 PM
Updated by: