Skip to main content

I’m working on a zap that automatically creates activity entries in Clio based on the emails I receive from courts when the clerk updates the record. My goal is to have the activity entries in Clio reflect the date the hearing was held, rather than the date the the record is updated. In most cases, the clerk makes the entries the same the same day as the hearing. In these cases, it’s easy to extract the proper date with Formatter, because it always follows the phrase “Filing Date” in the body of the email. However, in cases where the clerk does not make the entry the same day as the hearing, this doesn’t work. The date the hearing actually took place, doesn’t always follow the same phrase (there are several phrases it might follow.) Is there a way to isolate this date? Is it possible to extract ALL of the dates and choose the earliest of them?

 

I’m not a very sophisticated user. I suspect I’ve been using Formatter to accomplish things that are better done with other tools I’m not familiar with. 

 

Thank you for any help.   

Hi there ​@JLO 👋

Happy to lend a hand here! With Formatter you could use the Text > Extract Pattern action extract all dates using a regex pattern. For example if the date was in the format dd/mm/yyyy or mm/dd/yyyy you could use this Regex pattern:

\b\d{1,2}/\d{1,2}/\d{3,4}\b

And set the Match All field to Yes:

856da93d3508b880dc28191172ee3e8e.png
Which would give you all the dates present in that email (assuming they are in that same date format):

4659ab43148ed7c8bf27356169caa85c.png
You can find out more about how to use regex in Zaps here: Find text with regular expressions in Zaps

Alternatively, perhaps you could use Email Parser as the trigger instead? See Trigger Zaps from new parsed emails to learn more.

If you do give that regex pattern a try and run into any trouble just let me know—happy to assist further! 🙂


Okay, and then how do I choose the earliest of those dates?


Ah, sorry for missing that part ​@JLO

In that case it would be better to use a Code step to pick out the earliest date as well as extract all the dates from them. Code steps are a bit more advanced but we have an AI feature that can help to generate the necessary code for you: Generate a Code step using AI (Beta)

For example I used the AI feature in a Run Python (Code by Zapier) action and it suggested this code:


import re
from datetime import datetime

email_text = input_data.get('emailText', '')

# Regular expression to match dates in the format MM/DD/YYYY
date_pattern = r'\b(\d{1,2}/\d{1,2}/\d{4})\b'
date_strings = re.findall(date_pattern, email_text)

# Convert date strings to datetime objects
dates = adatetime.strptime(date_str, '%m/%d/%Y') for date_str in date_strings]

# Sort dates to find the earliest one
dates.sort()

# Prepare the output with the list of date strings and the earliest date
output = {
'dates': date_strings,
'earliest_date': dates:0].strftime('%m/%d/%Y') if dates else ''
}

My setup looked like this:

39008a0a8ef9b719e9896a58b1ad1695.png
And that was able to extract a list of the dates as well as identify the earliest one:

b8dee01a85cb6dc626e912caf193d8f5.png

Can you give that a try and let me know if that works better?


Reply