Attach XML to Flow Designer

Evan Duran
Kilo Guru

Hello,

I currently manually insert XML text as shown below. I also have my script step to parse data. I have much larger XML files that I would like to attach rather than just copy paste into this field. How can I go about doing this? SFTP Server?

EvanDuran_0-1721408717814.png

EvanDuran_1-1721408766177.png

 

 

1 REPLY 1

Samaksh Wani
Giga Sage
Giga Sage

Hello @Evan Duran 

In ServiceNow Flow Designer, you can integrate with an SFTP server to handle larger XML files as part of your workflow. Here’s how you can approach it:

Setting Up SFTP Integration in ServiceNow Flow Designer

  1. Create an Integration: First, you'll need to set up an integration in ServiceNow that allows Flow Designer to connect to your SFTP server. Here’s a general outline of the steps:

    • Navigate to Integration Hub: Go to Integration Hub > Studio in your ServiceNow instance.
    • Create Integration: Create a new integration of type 'Scripted REST API'. This integration will act as a bridge between Flow Designer and your SFTP server.
    • Define Credentials: Configure credentials within the integration to securely store SFTP server login information (e.g., hostname, username, password).
  2. Develop Scripted REST API: Write the necessary script to handle SFTP operations (like file upload) within the Scripted REST API. ServiceNow uses scripting to interact with external systems. Ensure your script can handle file uploads securely and efficiently.

    • Example Scripted REST API for uploading files to SFTP (Java script):
    (function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
        var sftp = new Packages.yourpackage.SFTPClient(); // Instantiate your SFTP client class
        var fileName = request.body.data.fileName; // Extract filename from request
        var fileContent = request.body.data.fileContent; // Extract file content from request
    
        // Connect to SFTP server
        sftp.connect("sftp.yourserver.com", "username", "password");
    
        // Upload file
        sftp.upload(fileName, fileContent);
    
        // Disconnect from SFTP server
        sftp.disconnect();
    
        // Return response
        response.setStatus(200);
        response.setContentType('application/json');
        response.getStreamWriter().writeString('{"status": "File uploaded successfully"}');
    })(request, response);
    
    • Replace yourpackage.SFTPClient() with the actual implementation or library you're using to handle SFTP connections and uploads.

Create Flow in Flow Designer: Once your integration is set up and tested, you can create a flow in Flow Designer to orchestrate the process of uploading and processing XML files from your SFTP server.

 

Please mark my response as accept, if you find it helpful.

 

Regards,

Samaksh Wani