Ankur Bawiskar
Tera Patron

@Andrea34 

try this

(function executeScheduleJob() {
    try {
        var changeRequestSysId = "26ab7d4133e69a10ab0585434d5c7b73"; // Sys ID del Change Request en ServiceNow
        var attachmentUrl =
            "https://instance.atlassian.net/rest/api/2/attachment/content/167229"; // URL del archivo adjunto en Jira
        var attachmentName = "DVAN - TC no se visualiza en la app.xlsx";
        var attachmentMimeType =
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

        var jiraUrl = "https://banreservas-sandbox-149.atlassian.net";
        var email = "catiles@banreservas.com";
        var apiToken =
            "your_token";

        var auth = "Basic " + GlideStringUtil.base64Encode(email + ":" + apiToken);

        var attachmentData = new sn_ws.RESTMessageV2();
        attachmentData.setHttpMethod("GET");
        attachmentData.setEndpoint(attachmentUrl);
        attachmentData.setRequestHeader("Authorization", auth);

        request.saveResponseBodyAsAttachment('change_request', changeRequestSysId, attachmentName); // added newly

        var attachmentResponse = attachmentData.execute();
        var attachmentResponseBody = attachmentResponse.getBody();
        var fileBytes = GlideStringUtil.base64DecodeAsBytes(attachmentResponseBody);
        gs.info("FILE BYTES", fileBytes);
        var attachmentStatus = attachmentResponse.getStatusCode();

        if (attachmentStatus !== 200) {
            gs.error(
                "Error al descargar el adjunto de Jira. Código de estado: " +
                attachmentStatus
            );
            return;
        }




    } catch (error) {
        gs.error("Error en el Scheduled Job: " + error);
    }
})();

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post