cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Count number of digits in email subject

Hi all,

 

I'm trying to build some logic into a business process. The requirements I need to fulfill is that if an email is received, look at the subject line. If the email subject contains ONLY a 10 digit number, then continue on to the rest of the flow. I've got the rest of my process figured out, but this part is stumping me.

Can someone point me in the right direction to get started?

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Hi @Scotty182002  & @edgonzales ,

 

To achieve your requirement we need to utilise expression functions such as length and substring. Please see below steps:

 

1.  Here we need to setup a trigger when email receives. 

n1.png

2. Next step we need to capture the subject text of the email. So declare a string variable called 'SubjectNumber'.

n2.png

3.  Next declare an integer variable called 'Index' and set the default value as zero. This is later used for extracting the each email text content using the expression function substring.

n3.png

4. Next declare another string variable called 'SubjectEachCharacter'. This is used later for storing the individual characters from the subject text of email.

n4.png

5. Next declare our last variable called 'IsNumeric' type as boolean. This is used for storing the final result of the email text subject is numeric or not.

n5.png

6. Next flow step is our core logic which extracts each character one at a time and check the character is a digit or not. So acheive this we need to create a Do Until loop where the index is equal to 10. Remember the index variable we created earlier.  The inside the do until loop we have two more steps to add.

 

First step is for extracting each character using an expression function.

substring(triggerBody()?['Subject'],variables('index'),1)
This is stored under the variable called 'SubjectEachCharacter'.
 
Second step is the conditon to check the 'SubjectEachCharacter' is equal to '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'.
 

n6.png

 

Here is the conditional flow. Feel free to extend the conditions. Here I am only checking two integers only which is 0 and 1. Remeber the condition is also under the Do Until loop.

n7.png

7. The condition Yes/No flow actions are below. Remember again this is also inside the Do Until loop.

So for the true condition we are setting IsNumeric to true and added the next step called Increment variable where I increment the index to 1. So that when the next iteration it picks each character at a time using the substring function we created above. Nice and easy.

For the false condition all we need to do is set the IsNumeric to false. We don't need to iterate rest of the subject text so the tick is set the index variable to 10.  So it nicely exists the loop immediately. Wish there was some break functions available. Hopefully in future 🙂

n8.png

8. We have finished the core logic and next step is out side the Do until loop which is checking the IsNumeric field true or false. Here you feel free to extend the other flow steps.

n9.png

Now at this stage the flow build is finished. Next you need to trigger an email and test this. Also remember you need to check the length of the email text is 10 by using the expression function length after the trigger step. Under the Yes condition you need to add all of the flow steps 2 onwards. The above screenshot is not covering that. This specifically focusing on how to determine the text is numeric or not. If you having any issues with this then let me know.

 

Finally here are my test results for subject text '0101010101'. We expect this should classified as numeric.

 

n11.png

 

My another test results for '101010101a'. Here we are expecting the final result to false.

n12.png

 

Please try the above and let me know the results. 

 

Good luck

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

View solution in original post

11 REPLIES 11
Super User III
Super User III

Hi @Scotty182002 ,

 

Are there any specific patterns for the subject. Could you post some examples of subject text?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

Hi @abm , the desired subject would only be "0123456789". It could be any combination of numbers totaling up to 10 digits, it's an order number if that helps.

What we want to have happen is that if the email contains anything other than a 10 digit number, reject the email message with a reply back to the user essentially saying they need to resubmit and follow the diretions this time.

So, correct subjects: "0123456789", "8013937829", "1002938590" - Any combination of 10 numbers with no spaces.

Incorrect subjects: "Vendor order -jane doe"

"here is your order"

"re: quote"
"order paperwork" etc....

Thanks for the assistance!

 

@Scotty182002 

You could probably use length(), but the problem there is that it won't care if it's a number or a letter.  Also, you might run into weirdness if you try to convert your subject to an integer AND it has a leading zero (will most likely get trimmed out and throw off the count). 

What is the next step in the process?  Could we automatically compare the subject to a known list of order numbers and return an error if a match isn't found?

Keep us posted.

 

-Ed-

 

If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

@edgonzales 

Can't compare to a list of known numbers. We've got hundreds of thousands of order numbers that flow doesn't have access to. Length alone wouldn't work as they might be able to type in a person's name and have it meet the 10 character criteria.

The next step in the process just takes the email, strips the attachment out, saves it to a folder with file name that = equals the order number from the subject line.

There's another business process(outside of Flow) that looks at that folder and imports the files based on the file names. If the file name ends up being something other than an order #, the process ends in an exception that someone has to work manually. Trying to put the responsibility on the sender to send in things in the right format first.

Thank you

Hi @Scotty182002 ,

 

I am working on this now. Will get back to you.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Super User III
Super User III

Hi @Scotty182002  & @edgonzales ,

 

We need to utilise expression functions such as len, substring. Please follow below steps.

 

1. When new email arrives.

n1.png

2. Next step you need to check the length of the subject is 10 or not. So add an if condition, under the true statement add all the below flow actions. The below actions is for to check whether the subject line is numeric code or not.

 

3.  Declare a variable called SubjectText. Here we capture the subject text from the email.

n2.png

4. Add next integer variable called index and initialise to zero.

n3.png

5. Next declare another variable called SubjectEachCharacter. Later we need to extract each characters from the subject text. 

n4.png

6. Next declare another variable called 'IsNumeric'. Boolean type. 

n5.png

7. Next step we need to add a Do Until loop where index is equal to 10. The plan is to extract each characters and check if it is numeric digit or not. See below.

n6.png

 

Above for GetEachCharacter I have used a substring expression like this.

substring(triggerBody()?['Subject'],variables('index'),1)
This will get one character at a time. Next step is to check the characters. I will expand the condition below.
n7.png
Note: Here you can expand the other conditions 2,3,4,5,6,7,8 & 9
8. Next under the condition set the isnumeric boolean flag to true or false. Also increment the index to 1. You might be noticed that for the no condition I have set the index value to 10. The reason for this is we don't want to iterate rest of the values and looping all the way to 10 times.  See below.
n8.png
 
9. Finally add the below step outside the Do until loop to check the subject text is numeric or not.
n9.png
 

Under the yes condition you can add your rest of the flow actions.

 

Test Results

 

For subject line '0101010101'. This we expect to pass.

n11.png

 

For subject line '01010101a0'. This we expect to fail.

n12.png

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Super User III
Super User III

Hi @Scotty182002  & @edgonzales ,

 

I have posted my reply earlier. It did contain quite a lot of screenshots. I have edited my post and now I am getting the below screen.

n14.png

 

n0.png

 

Could someone please explain?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

@abm I don't think I've ever had that happen here. Maybe delete and try recreating from scratch?

Hi @Scotty182002@edgonzales 

 

This is the first time it happened. The good news is I got a  working solution for you and the bad news is I have to recreate all the steps again. I thought someone from the community (Administrator) could approve it. It did contained quite a lot of screenshots and could be classified as spam. Anyway I will submit another post for you now. Give me few minutes.

 

Thanks 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Super User III
Super User III

Hi @Scotty182002  & @edgonzales ,

 

To achieve your requirement we need to utilise expression functions such as length and substring. Please see below steps:

 

1.  Here we need to setup a trigger when email receives. 

n1.png

2. Next step we need to capture the subject text of the email. So declare a string variable called 'SubjectNumber'.

n2.png

3.  Next declare an integer variable called 'Index' and set the default value as zero. This is later used for extracting the each email text content using the expression function substring.

n3.png

4. Next declare another string variable called 'SubjectEachCharacter'. This is used later for storing the individual characters from the subject text of email.

n4.png

5. Next declare our last variable called 'IsNumeric' type as boolean. This is used for storing the final result of the email text subject is numeric or not.

n5.png

6. Next flow step is our core logic which extracts each character one at a time and check the character is a digit or not. So acheive this we need to create a Do Until loop where the index is equal to 10. Remember the index variable we created earlier.  The inside the do until loop we have two more steps to add.

 

First step is for extracting each character using an expression function.

substring(triggerBody()?['Subject'],variables('index'),1)
This is stored under the variable called 'SubjectEachCharacter'.
 
Second step is the conditon to check the 'SubjectEachCharacter' is equal to '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'.
 

n6.png

 

Here is the conditional flow. Feel free to extend the conditions. Here I am only checking two integers only which is 0 and 1. Remeber the condition is also under the Do Until loop.

n7.png

7. The condition Yes/No flow actions are below. Remember again this is also inside the Do Until loop.

So for the true condition we are setting IsNumeric to true and added the next step called Increment variable where I increment the index to 1. So that when the next iteration it picks each character at a time using the substring function we created above. Nice and easy.

For the false condition all we need to do is set the IsNumeric to false. We don't need to iterate rest of the subject text so the tick is set the index variable to 10.  So it nicely exists the loop immediately. Wish there was some break functions available. Hopefully in future 🙂

n8.png

8. We have finished the core logic and next step is out side the Do until loop which is checking the IsNumeric field true or false. Here you feel free to extend the other flow steps.

n9.png

Now at this stage the flow build is finished. Next you need to trigger an email and test this. Also remember you need to check the length of the email text is 10 by using the expression function length after the trigger step. Under the Yes condition you need to add all of the flow steps 2 onwards. The above screenshot is not covering that. This specifically focusing on how to determine the text is numeric or not. If you having any issues with this then let me know.

 

Finally here are my test results for subject text '0101010101'. We expect this should classified as numeric.

 

n11.png

 

My another test results for '101010101a'. Here we are expecting the final result to false.

n12.png

 

Please try the above and let me know the results. 

 

Good luck

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

View solution in original post

@abm wow, that was a lot more involved than I initially thought it was going to be. Thank you for taking the time to go through that!

I'll be testing this out today or Monday. I really appreciate the work you put in to helping me!

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (5,517)