Get Content from ECC Queue Payload XML attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 03:46 PM
Hi,
I have a flow that triggers a PowerShell to retrieve a csv from a Shared folder in Flow Designer. I got my action to retrieve the information by creating a ECC Queue record. It encodes the csv and then I decode it when it return to ServiceNow. However, in the input record it attaches the Payload to an attached file.
I need to get the content from this file, but I can't use getContent because this is not a scoped application.
How can I get the information from this attachment so that I can decode it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 08:51 AM
that scripts works for me:
var queue = new GlideRecord('ecc_queue');
queue.get('bb99070b87a6b550696164eabbbb353f'); // value for tests, to be changed
var result = '';
var payload = '';
var doc = new XMLDocument2();
if (queue.payload == '<see_attachment/>'){
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', 'ecc_queue');
grAttachment.addQuery('table_sys_id', queue.sys_id);
grAttachment.query();
if(grAttachment.next()){
var attachmentSysId = grAttachment.sys_id;
var payloadAttachment = '';
var is = new GlideSysAttachment().getContentStream(attachmentSysId);
var reader = new GlideTextReader(is);
var ln = ' ';
while((ln = reader.readLine()) != null) {
payloadAttachment += ln;
}
doc.parseXML(payloadAttachment);
}
}else{
doc.parseXML(queue.payload);
}
payload = doc.getFirstNode('//output').getTextContent();
result = JSON.parse(payload);
it checks if the payload is in the field or in attachment first, then if it is in the attachment proceed to get then read the file, puts everything in the payload variable then parse it (because i'm expecting to get a JSON from the MID server).
so at the end wherever it was stored I have the MID server answer in the result variable.
don't forget to change the sys id on line 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 02:27 PM
HI Can you please explain how you decoded the response from input ECC Queue record and attached to the record.
It will be very helpful, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 06:36 AM
Hi, here it is the same code with comments for explanation:
var queue = new GlideRecord('ecc_queue');
queue.get('bb99070b87a6b550696164eabbbb353f'); // value for tests, to be changed
var result = '';
var payload = '';
// initiation of variables used later
var doc = new XMLDocument2();
// initiation of XMLDocument2 object that will be used to parse the XML from the ecc input
if (queue.payload == '<see_attachment/>'){
// if the payload is in the attachment, servicenow just puts "<see_attachment/>"in the payload, if this is the case, we get in the condition
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_name', 'ecc_queue');
grAttachment.addQuery('table_sys_id', queue.sys_id);
grAttachment.query();
// look for the attachment of the ecc
if(grAttachment.next()){
var attachmentSysId = grAttachment.sys_id;
//if attachment found, put the sys_id in variable
var payloadAttachment = '';
var is = new GlideSysAttachment().getContentStream(attachmentSysId);
var reader = new GlideTextReader(is);
var ln = ' ';
while((ln = reader.readLine()) != null) {
payloadAttachment += ln;
}
// this part read through the attachment and put its content in the payloadAttachment variable
doc.parseXML(payloadAttachment);
// parse the XML content of the attachment
}
}else{
doc.parseXML(queue.payload);
// if the payload was not in attachment but in the payload field, just parse it
}
payload = doc.getFirstNode('//output').getTextContent();
// get content inside the "output" tag of the XML
result = JSON.parse(payload);
// for my script, the output was a JSON string so I am parsing it to a javascript object in the result variable
hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2025 08:12 AM
@Dazler - Can you help with powershell script you wrote