Hi @JM-11031334-0,
Based on your explained issues - handling tracking number is easy need a bit of work around.
But bad luck is you need patience to handle the date as its format varies, you have tackle this varying different techniques.
Let's dive into the issues:
Issue 1: Tracking Numbers
To make sure the Tracking # field remains empty when the subject line does not contain a tracking number in parentheses, you can modify the expression to check for the presence of parentheses first. If they exist, extract the tracking number; if not, return blank. - you can do this ff an only if you are sure tracking number coming inside parenthesis - at least we have to have something to check, right?
Try this expression in Power Automate:
if(
and(
contains(triggerOutputs()?['body/subject'], '('),
contains(triggerOutputs()?['body/subject'], ')')
),
first(split(last(split(triggerOutputs()?['body/subject'], '(')), ')')),
''
)
Issue 2: Due Dates
The Due Date extraction challenge, as it varies in the email body
Regular Expressions (Regex) can be our friend:
- Let's use the "Compose" action with an expression that applies a regex pattern to find date-like strings in the email body.
- Example regex patterns can match formats like
MM/DD/YYYY, M/D/YYYY, or full month names like February 25, 2026.
- Power Automate doesn’t have built-in regex, but you can use the "Match" function in expressions
We have to try Multiple Date Extraction options:
- Use multiple Compose actions with different expressions to extract dates in different formats. For example, one expression to extract
MM/DD/YYYY using substring() and indexOf(), another to extract Month DD, YYYY using split() and contains().
- Let's use a condition to check which extraction succeeded and pick the valid date. Get a narrow clue from here.
Convert Extracted Text to Date:
Either ways - if you have the date in place, use the formatDateTime() function to convert the extracted date string to a date type compatible with SharePoint. And at last if parsing fails, return null or empty to avoid flow failure.
And lastly, If no recognizable date is found, set the Due Date field to null as you prefer.
// Compose action expression to extract date after "Due"
trim(
first(
split(
last(
split(triggerOutputs()?['body/body'], 'Due')
),
'.'
)
)
)
Note: This extracts the text after "Due" up to the next period, which you can then try to parse as a date.
I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!