How to Use OnStart Transform Script to Process Only Excel Attachments

schetry
Tera Contributor

Hi Community,

I have an inbound email action that receives Excel files along with other attachments (e.g., signature images). The email's Excel attachment needs to be processed through an import set and transform map.

Currently, the transform is failing if a non-Excel file (like a .png or .jpg) is the first attachment, because the loader tries to parse it as a spreadsheet.

My Goal:
I want to add logic in the OnStart Transform Script to process only attachments ending with .xls or .xlsx and ignore any others.

What I Tried:
I attempted filtering using file_nameENDSWITHxls^ORfile_nameENDSWITHxlsx in my script, but it seems the transform still processes all attachments.

My Question:
Can someone share an example OnStart Transform Script that:

  • Checks the import set attachments

  • Ignores all non-Excel files

  • Ensures the transform only runs on the Excel attachment

Has anyone implemented this kind of filtering successfully in an OnStart Transform Script?

Thanks in advance!

2 ACCEPTED SOLUTIONS

@schetry 

 

Use below link to filter the attachments from email to data source before running transform,

 

https://www.servicenow.com/community/developer-blog/loading-data-from-an-email-attachment/ba-p/22797...

 

If this helps to resolve your query, accept the solution and close the thread.

 

Thanks,

Bhuvan

View solution in original post

This post will absolutely help, but I would personally move everything to Flow designer. The actions that are already available, will help you in copying the excel file through simple lookups.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

4 REPLIES 4

Mark Manders
Mega Patron

How are you processing them? Why not only copy the excel tot the data source that has the transform map running on it? It sounds like your issue isn't in processing it, but that you are copying too many attachment.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

I’m already trying to copy only the Excel attachment to the Data Source before running the transform map.
However, the issue is that the incoming email sometimes contains multiple attachments (like signature images) in addition to the Excel file.

Do you have a script example for copying only attachments with .xls or .xlsx extensions from the email to the Data Source, so that other file types are completely ignored before loading the import set?

@schetry 

 

Use below link to filter the attachments from email to data source before running transform,

 

https://www.servicenow.com/community/developer-blog/loading-data-from-an-email-attachment/ba-p/22797...

 

If this helps to resolve your query, accept the solution and close the thread.

 

Thanks,

Bhuvan

This post will absolutely help, but I would personally move everything to Flow designer. The actions that are already available, will help you in copying the excel file through simple lookups.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark