Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

ServiceNow Mulesoft Integration to move excel from ServiceNow to Mulesoft and then SAP?

VIKASM535239375
Kilo Sage

How to complete ServiceNow Mulesoft Integration to move excel from ServiceNow to Mulesoft and then SAP for Custom Application in Australia?

1 REPLY 1

KartikM49574975
Kilo Sage

 

Hi @VIKASM535239375 

You can split this integration into two parts.

 

Part 1: ServiceNow → MuleSoft

  1. Make sure the Excel file is stored as an attachment (sys_attachment) on your custom app record.
  2. Ask the MuleSoft team for the API endpoint, authentication details (OAuth or Basic) and the expected payload format.
  3. Create an outbound REST Message (System Web Services > Outbound > REST Message) pointing to the MuleSoft endpoint. [github.com]
  4. Send the file using one of these options, depending on what MuleSoft expects:

Option When to use How

Binary bodyMuleSoft accepts the raw filerequest.setRequestBodyFromAttachment(attachmentSysId) [servicenow.com]
JSON + Base64MuleSoft expects a JSON payload with the file content insideRead the attachment with GlideSysAttachment.getBytes() and encode it with GlideStringUtil.base64Encode() [support.se...icenow.com]
Multipart/form-dataMuleSoft expects the file plus other fieldsUse the IntegrationHub REST step with request type Multipart, where the attachment value is the sys_id of the attachment record. Don't set the Content-Type header manually. [servicenow.com]

 

Example for the Base64 option:

 

var gr = new GlideRecord('sys_attachment');
if (gr.get(attachmentSysId)) {
    var gsa = new GlideSysAttachment();
    var base64 = GlideStringUtil.base64Encode(gsa.getBytes(gr));
 
    var rm = new sn_ws.RESTMessageV2('MuleSoft_Integration', 'post');
    rm.setRequestHeader('Content-Type', 'application/json');
    rm.setRequestBody(JSON.stringify({
        fileName: gr.getValue('file_name'),
        contentType: gr.getValue('content_type'),
        fileContent: base64
    }));
    var response = rm.execute();
    gs.info('MuleSoft status: ' + response.getStatusCode());
}

 

Wrap the call in a Script Include and trigger it from a Business Rule, UI Action or Flow, depending on when the file should be sent.

 

Part 2: MuleSoft → SAP

This is configured on the MuleSoft side. Mule receives the file, then maps and transforms it for SAP (for example with DataWeave) and calls the SAP interface. Your MuleSoft/SAP team will need to confirm the SAP endpoint and format.

Other things to check

  • Use a Credential record or Connection alias for authentication. Don't hardcode secrets in the script.
  • If MuleSoft sits on a private network, you may need a MID Server.
  • Log the response status and body, and add retry or error handling for failed calls.
  • If the file is large, check the payload size limits on both ServiceNow and MuleSoft.

Reference: the community article on sending attachments to third-party tools covers the same approach. [servicenow.com]

 

Thanks.

If my response helped, please mark it as correct.