Trying to find part of a filename in an array of attachments

:bullseye: What is your goal?

identify a file type from a filename that is part of an array of attachments.

:thinking: What is the problem & what have you tried?

Webhook receives an array of attachments. in my case, a PDF, HTML, MD and JSON. 4 files.

I am trying to map each file based on their file type.

the array contains

  1. filename
  2. url

the filename ends with either .html, .pdf, .md and .json.
We always receive all 4 files.

I’ve tried the following
{{get(map(1.task_detail.attachments; “url”; “file_name”; contains(1.task_detail.attachments.file_name; “.html”)); 1)}}

and
{{get(map(1.task_detail.attachments; “url”; “file_name”; “.*\.pdf”); 1)}}

both empty results. If I explicitly state the filename then it works. e.g.

{{get(map(1.task_detail.attachments; “url”; “file_name”; “myfile.pdf”); 1)}}

Is there a way to return the URL when the filename contains a partial match or contains “.html” etc or endsWith() etc…?

Thanks!

1 Like

Hey there,

contains() returns a boolean true or false. So you should adapt your formula to something like if(contains(whatever) = true) then do something.

Then the second thing - map() doesn’t support partial matches, so you will need the entire file name in it.

Can you share some sample inputs you are trying to work with?

I was able to resolve this issue and thanks for your assistance and response.

Since the map() does not support partial matches and the filename will be different each run I could not use map() in this case.

What did work was to use and Iterator and Router, adding a route for each file. I set a filter on each route to only run if the filename contained the extension. And added a Set Variable to store the URL. The last route, processes all files. However, the magic (and thing that confused me when I first tried this method) was to add a filter AFTER the Get Variables to only continue if all variables were not empty as I need all files. Previously this final route would always fail because it ran once for each file and I needed it to only run when all files had been stored in their respective variables.

2 Likes