save xml as attachment ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2013 03:01 AM
hi there!
any pointers to store the xml of current record as a related attachment record in attachments table ?
cheers!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2013 11:27 AM
Option 1: External Tool/Code
https://wiki.servicenow.com/index.php?title=Exporting_Data#Calling_URL_Exports_Programmatically
1.Call the unload URL from an external source
https://instanceName.service-now.com/incident.do?XML&sys_id=ed391d31293201002e93940592a4052e&useUnloadFormat=true
2.Write to a file location and upload file back to a destination of choice
3.This option may be slower because of disk IO involved.
Option 2: Use ECC Queue
1.Generate XML manually for the table/record you are sitting on; I am sure there are better ways to export the current record into XML
2.base64Encode your xml string before you write to the ecc queue payload
3.The sample business rule below will send the xml file to an Incident record specified.
attachXML();
function attachXML() {
//create the xml unload of the record manually 😞
var xmlString = 'xmlFileHere';
var StringUtil = Packages.com.glide.util.StringUtil;
var gr = new GlideRecord('ecc_queue');
gr.initialize();
//OOB attaches the payload in base64 to the table defined in source field below
gr.agent = 'AttachmentCreator';
gr.topic = 'AttachmentCreator';
gr.name = current.number + '.xml:text/xml';
//update table name & sys_id as needed
gr.source = 'incident:ed137f4e45ae45009673bd09e0974961';
gr.queue = 'input';
gr.state = 'ready';
gr.payload = StringUtil.base64Encode(xmlString);
gr.insert();
}
4.HTH
Subash Biswas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2013 03:53 AM
Thanks for the suggestion. currently I am working on a alternate solution to my problem which avoids xml attachment.
I will try this later, thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 09:38 AM
instead of having "var xmlString = 'xmlFileHere';" how can I put the entire XML of the CI that I want to export?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2013 04:22 AM
There is actually a very simple way, Here is the way you can do it:
var xml = '<xml>'+
'<number>'+current.number+'</number>'+
'<state>'+current.state+'</state>'+
'</xml>';
var attachment = new Attachment();
var attachmentRec = attachment.write('incident', current.sys_id, "record.xml", "text/xml", xml);
gs.addInfoMessage('An attachment is created with sys_id and attached to this incident'+ attachmentRec);
This is the idea.