Hello @jacobo 

 

Ok I got it , there is some data here that's not to be in Excel. It's not decoding properly for Excel format. I am aware about  function maybe try that - 

 

Try below 👇 script - 

 

var attachment = new GlideSysAttachment();

 

var agr = attachment.getAttachments('sc_req_item', 'ab480111c368ea9cda547fe4e4013143');

 

while (agr.next()) {

    gs.info(agr.getValue('file_name'));

    gs.info(agr.getValue('sys_id'));

 

    var Attachname = agr.getValue('file_name');

    var attachmentSysId = agr.getValue('sys_id');

 

    var boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';

 

    var bodyHeader = '';

    bodyHeader += '--' + boundary + '\r\n';

    bodyHeader += 'Content-Disposition: form-data; name="files"; filename="' + Attachname + '"\r\n';

    bodyHeader += 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n';

 

    var bodyFooter = '\r\n--' + boundary + '--\r\n';

 

    var restMessage = new sn_ws.RESTMessageV2();

    restMessage.setHttpMethod('POST');

    restMessage.setLogLevel('all');

    restMessage.setEndpoint('External URL');

    restMessage.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);

 

    // Set the first part of body

    restMessage.setRequestBody(bodyHeader);

 

    // Attach the file content directly (raw binary)

    restMessage.setRequestBodyFromAttachment(attachmentSysId);

 

    // Append the footer manually (after the binary)

    restMessage.setStringParameterNoEscape('body_end', bodyFooter);

 

    try {

        var response = restMessage.execute();

        var responseBody = response.getBody();

        gs.info('Response: ' + responseBody);

    } catch (e) {

        gs.error('Error sending Excel attachment: ' + e);

    }

 

    break; // only handle the first attachment

}

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY