Send only .pdf and .txt files (attachments)

Originally asked by Ron Becker on 07 February 2023 (original question)


There is a possibility to limit the attachments imported with the incoming script. The following line works fine.

issue.attachments = replica.attachments.findAll { attachment -> attachment.filename.endsWith(“.pdf”) }

When we only want to accept .pdf and .txt I changed it into

issue.attachments = replica.attachments.findAll { attachment -> attachment.filename.endsWith(“.pdf”,“.txt”) }

unfortunately this gives an error. Is it possible to define multiple file extensions?


Answer by Serhiy Onyshchenko on 08 February 2023

Hey, Ron Becker

Thanks for asking on community!
You could do it with || operator or the array list check:

issue.attachments = replica.attachments.findAll { attachment -> attachment.filename.endsWith(".pdf") || attachment.filename.endsWith(".pdf") }

or

issue.attachments = replica.attachments.findAll { attachment -> [".pdf",".txt"].any { ext -> attachment.filename.endsWith(ext) } }

Happy Exalating!
Serhiy


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.