AWS S3 Integration: Building of attachment file through flow designer

Josh Pirozzi
Kilo Sage

Hi everyone!

We've set up the integration between our Dev Instance and AWS S3, and what we are trying to accomplish is:

- Through Flow Designer, look up Catalog Task Records that have been assigned to a specific Assignment Group

--- Our initial run will be open-ended (to pull all historical records), but then going forward we'll only look-up records for that day.

- Once all Catalog Task Records have been found, then pull specified fields from each of those SCTasks and compile into a single file, as an attachment, and upload to a pre-determined AWS S3 bucket.

 

I've gone through the steps to confirm that the connection between ServiceNow & AWS is good, but the breakdown point for me is in building the attachment file. As this is my first attempt, and haven't been able to locate any posts/articles detailing this yet, I've taken a stab at building an action where:

- Input = List.Catalog Task (Table)

- Payload Builder Step = I've called out each of the necessary fields and selected JSON as the Output Format

- Output = Data Pill Picker which selects the Payload Builder Step > Payload (String)

 

I then associate this Action to my Flow where I have:

- Step 1: Look up Catalog Tasks where Assignment Group is GROUP NAME

- Step 2: My AWS S3 Action (Payload Builder)

- Step 3: Check Attachment

- Step 4: Upload to AWS S3 Bucket

 

Each time I've tested this Action & Flow, it's showing as successful, but displays Attachment as False & doesn't create the file. I know that I'm missing something either in my Action or Flow, but I'm not positive on what it might be.

 

Thank you!

1 ACCEPTED SOLUTION

Hi @Josh Pirozzi 

 

Without providing a full blown solution I could recommend you look at Ankur's post on generating a CSV file with Catalog variables from a RITM:

https://www.servicenow.com/community/developer-blog/generate-csv-file-with-the-catalog-variables-and...

 

I also tested building out a simple action (script step below) which generates a CSV file to a SCTASK record using some input values:

(function execute(inputs, outputs) {

  	// hardcoding CSV header row
    var csvHeaderRowList = ["SCTASK Number", "Assignment Group"];
  	var csvHeaderRow = csvHeaderRowList.toString();
  
  	// populate values from action inputs
    var csvValueRowList = [inputs.taskNumber, inputs.assignmentGroup];
	var csvValueRow = csvValueRowList.toString();
    
    // generate CSV document
  	var document = csvHeaderRow + "\n" + csvValueRow;
  
  	// write CSV document to SCTASK record
    var catalogTaskAttachment = new GlideSysAttachment();
    var catalogTask = new GlideRecord('sc_task');
    catalogTask.get(inputs.taskSysID);
    catalogTaskAttachment.write(catalogTask, "catalogTaskFields.csv", "text/csv", document);

})(inputs, outputs);

 

You would have to figure out the best way to enhance and refactor the above if you want to capture additional values and also how you would retrieve the generated attachment from the SCTASK record.

View solution in original post

4 REPLIES 4

Geoff_T
Mega Sage

Hi, check out my article on creating an attachment via Flow Designer. It might help you with some ideas for your use case:

https://www.servicenow.com/community/developer-articles/generate-an-attachment-via-custom-flow-desig...

 

Geoff

Hi @Geoff_T - Thank you for the info & I came across your article just before you responded. This attachment build action brings me part of the way there, but would have any experience in populating Catalog Task/Request Item data and compiling it into the CSV file? I'm working on expanding the input section to include the additional fields that are being requested, but am unsure on if I'm doing this correctly. 

 

I don't have a ton of scripting experience, and wanted to double-check if just including these fields on the upper portion of the script step is enough, or will I also need to call out the data fields in the written script as well?

Hi @Josh Pirozzi 

 

Without providing a full blown solution I could recommend you look at Ankur's post on generating a CSV file with Catalog variables from a RITM:

https://www.servicenow.com/community/developer-blog/generate-csv-file-with-the-catalog-variables-and...

 

I also tested building out a simple action (script step below) which generates a CSV file to a SCTASK record using some input values:

(function execute(inputs, outputs) {

  	// hardcoding CSV header row
    var csvHeaderRowList = ["SCTASK Number", "Assignment Group"];
  	var csvHeaderRow = csvHeaderRowList.toString();
  
  	// populate values from action inputs
    var csvValueRowList = [inputs.taskNumber, inputs.assignmentGroup];
	var csvValueRow = csvValueRowList.toString();
    
    // generate CSV document
  	var document = csvHeaderRow + "\n" + csvValueRow;
  
  	// write CSV document to SCTASK record
    var catalogTaskAttachment = new GlideSysAttachment();
    var catalogTask = new GlideRecord('sc_task');
    catalogTask.get(inputs.taskSysID);
    catalogTaskAttachment.write(catalogTask, "catalogTaskFields.csv", "text/csv", document);

})(inputs, outputs);

 

You would have to figure out the best way to enhance and refactor the above if you want to capture additional values and also how you would retrieve the generated attachment from the SCTASK record.

Thanks & I appreciate your help @Geoff_T !!