How to send multiple attachment using Rest message for current incident

String
Kilo Sage

Hi team ,

we wrote a BR to capture the attachment and convert o base 64,But i am facing issue to capture the multiple attachment for current incident 

 

var tarRec = new GlideRecord(current.table_name);
var sa = new GlideSysAttachment();
var binData = sa.getBytes(current);
var base64Data = GlideStringUtil.base64Encode(binData);
var Attachment = new sn_ws.RESTMessageV2('ABC', 'XYZ');

Attachment.setStringParameterNoEscape('att_data', base64Data);
Attachment.setStringParameterNoEscape('att_type', current.content_type);

1 ACCEPTED SOLUTION

@kiranchand 

did you use variable substitution for setting the attachment data?

you should create variable substitution something like this and then set the data

{ "ABC":"12345",
"Mode":"Attachments",
 
"Attachments": "${attachmentData}"
}
 
find_real_file.png
Refer link below:
 
 
Regards
Ankur
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

i am following the above format ,so in the business rule i have to iterate the json body 

can you please share the reference code it would be helpful

@kiranchand 

something like this

var arr = [];

var currentRecordSysId = current.sys_id;

var tarRec = new GlideRecord('sys_attachment');

tarRec.addQuery('table_sys_id', currentRecordSysId);

tarRec.query();

while(tarRec.next()){
var sa = new GlideSysAttachment();
var binData = sa.getBytes(tarRec);
var base64Data = GlideStringUtil.base64Encode(binData);

var obj = [];

obj["att_data"] = base64Data;

obj["att_type"] = tarRec.content_type.toString();

arr.push(obj);

}

// call rest message and then set the body as below

var Attachment = new sn_ws.RESTMessageV2('ABC', 'XYZ');

Attachment.setStringParameterNoEscape('attachmentData', JSON.stringify(arr));

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

using the below json and added the attachment but Attachment data not moving to JSON body in rest message .!

 

Attachment.serStringParameterNoEscape('Attachments',JSON.Stringify(arr));

 

{ "ABC":"12345",
"Mode":"Attachments",
 
"Attachments": [{
 
"att_type": "",
"att_data":""}
]
}

@kiranchand 

did you use variable substitution for setting the attachment data?

you should create variable substitution something like this and then set the data

{ "ABC":"12345",
"Mode":"Attachments",
 
"Attachments": "${attachmentData}"
}
 
find_real_file.png
Refer link below:
 
 
Regards
Ankur
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader