Using Conditions for Attachments

Anna_272419
Anna_272419 Posts: 42
edited January 2020 in Questions

I’m trying to build a conditional process that extracts an Excel attachment from the trigger email and converts it to a table. The email that triggers the process will have two attachments- 1 PDF and 1 Excel. Since I don’t know if the order of the attachments will always be attachment1= PDF attachment2= Excel, I figured a condition would work best so I created two conditional steps:

Extract invoice Excel from email if attachment 1 is NOT a PDF (therefore should be Excel)

  • uses {{trigger-attachment}}
  • Condition: If fields["trigger-attachment-filename"] does not end with .pdf

And

Extract invoice from email if attachment 1 IS a PDF (therefore the Excel file is attachment 2)

  • uses {{trigger-attachment-2}}
  • Condition: If fields["trigger-attachment-filename"] ends with .pdf

But the triggers don’t seem to be working. What am I missing?
Thank you!

Answers

  • Thomas_937381
    Thomas_937381 Posts: 196
    edited January 2020

    Hey @Anna_272419,

    The best thing to do is use the trigger-attachments table, which contains an Extension column. From there, you can use Tables: Look up data in a column to return the File, which will be in a URL format. You'll need to then use Text: Find text next to other text to extract just the alphanumeric file ID from the URL.

    Once you have the file ID (it will be the --first-match field from the last step), you can use that as your input in the above steps.

    Thomas

  • Hi Thomas,
    Thank you for your response! That seems more complicated than it really should be.
    Will the Text: Find text next to other text function work if the file name of the invoice document is different every week?
    Thanks!

  • Hi @Anna_272419.

    The trigger-attachments table will have the following columns: file | Name | Type | Extension | Size in Bytes | Location

    Only two steps are needed to designate a specific file extension for use in your process. You may wish to add additional conditions if you want to accommodate a scenario where multiple attachments are present with the same extension.

    Tables: Look up data in a column
    In the Extension column, search for xlsx. You can return just the file column, as that is all that is needed. The value here is a URL in this format: https://{teamname}.pushbot.com/v1/teams/{teamname}/files/{fileid}/download

    Text: Find text next to other text
    In the url, you want to extract the {fileid} between this text: https://{teamname}.pushbot.com/v1/teams/{teamname}/files/{fileid}/download. Try the following configuration (you need to replace {teamname} with your company's team name):

    after-text: https://{teamname}.pushbot.com/v1/teams/{teamname}/files/
    before-text: /download

    One output from this step will be {prefix}--first-match. This will be your file {fileid}, which you can then dynamically reference in e.g. Excel: Convert spreadsheet to table. There should be no need to worry about the file name with an approach like this one.

  • Hi Thomas,
    Thanks so much for the detailed explanation! That worked!!