Getting 400 Message when sending attachment from one ServiceNow Instance to another

mr_zia
Giga Guru

Dear Team,

 

I am using custom application, from the Update Business Rule I am trying to send attachment to another ServiceNow instance but I am getting this error :

{"error":{"message":"Invalid file type: application/json","detail":null},"status":"failure"}

 

Here is my BR code, Experts please help how can i fix this issue 😞

 

var qry = 'table_name=incident^u_sent_flag=false^table_sys_id=' + current.sys_id;
 var att = new GlideRecord("sys_attachment");
    att.addEncodedQuery(qry);
    att.query();
    while (att.next()) {
        try {

            var r = new sn_ws.RESTMessageV2('x_mea_inte_Integration''Send Attachment');
            r.setStringParameterNoEscape('table_sys_id''611b0822fbb392103bf0f471beefdc06'); // sys_id hard coded for testing.
            r.setStringParameterNoEscape('table_name''incident');
            r.setStringParameterNoEscape('file_name', att.file_name);
            r.setStringParameterNoEscape("Accept""application/json");
            r.setStringParameterNoEscape("Content_type", att.content_type);
            r.setRequestBodyFromAttachment(att.sys_id);
            var response = r.execute();
            var responseBody = response.getBody();
            var httpStatus = response.getStatusCode();
            gs.info("Attachment Update Response Body : " + responseBody);
            gs.info("Attachment update status : " + httpStatus);
        } catch (ex) {
            var message = ex.message;
        }
1 ACCEPTED SOLUTION

mr_zia
Giga Guru

I am able to send attachment now.

On the Rest Message Send Attachment Endpoint I have to add : https://instance.service-now.com/api/now/attachment/file?table_name=${table_name}&table_sys_id=${tab...

 

This did the magic!

View solution in original post

5 REPLIES 5

mr_zia
Giga Guru

I am able to send attachment now.

On the Rest Message Send Attachment Endpoint I have to add : https://instance.service-now.com/api/now/attachment/file?table_name=${table_name}&table_sys_id=${tab...

 

This did the magic!