cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Extract part of a dynamic content value

I have a flow thatis triggered when a Cloud App Security alert is generated.  The flow takes the CompromisedEntity dynamic content value (which is the users email address) and puts it in the To field in an email action.

 

The email address format is firstname.lastname@company.com

 

I want to pull out everything from the start of the CompromisedEntity dynamic content until the first full stop "." into a variable which should give me the persons first name and then use that in the emails saluation i.e. Dear <firstname>

 

Im not a coder can someone help me how to get this to work?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Extract part of a dynamic content value

@Anonymous 

Hey there - This one is fun but really relies on the email addresses being consistent.  Essentially, we're going to use a nested Split() which breaks a string up into an array using whatever delimiter you choose.  I'll start from the inside out:

 

Presuming the email is first.last@email.com, use a Compose action and add the following expression:

 

Split(

 

Then click over to the dynamic content and put your dynamic email address in between the () of the Split.  Then add a comma and the first delimiter.  Here's what mine looks like:  split(triggerBody()['text'],'@')

This splits the string, 'first.last@email.com' into an array at the '@' with two values "first.last" and "email.com".  You can tell Flow, you're only interested in the first value of the array by adding a [0] at the end...  split(triggerBody()['text'],'@')[0]

This will give you only "first.last", so if we split that at the period and grab the first element again, you should end up with just the first name:  split(split(triggerBody()['text'],'@')[0],'.')[0]

20191022e.PNG

 

What do you think?  I don't normally do expressions, but I really like this one.  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.

View solution in original post

5 REPLIES 5
Highlighted
Super User
Super User

Re: Extract part of a dynamic content value

@Anonymous 

Hey there - This one is fun but really relies on the email addresses being consistent.  Essentially, we're going to use a nested Split() which breaks a string up into an array using whatever delimiter you choose.  I'll start from the inside out:

 

Presuming the email is first.last@email.com, use a Compose action and add the following expression:

 

Split(

 

Then click over to the dynamic content and put your dynamic email address in between the () of the Split.  Then add a comma and the first delimiter.  Here's what mine looks like:  split(triggerBody()['text'],'@')

This splits the string, 'first.last@email.com' into an array at the '@' with two values "first.last" and "email.com".  You can tell Flow, you're only interested in the first value of the array by adding a [0] at the end...  split(triggerBody()['text'],'@')[0]

This will give you only "first.last", so if we split that at the period and grab the first element again, you should end up with just the first name:  split(split(triggerBody()['text'],'@')[0],'.')[0]

20191022e.PNG

 

What do you think?  I don't normally do expressions, but I really like this one.  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.

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Extract part of a dynamic content value

Worked perfectly as I needed.  I'll be using that so much now I know how to get it to work.

 

Thanks.

Highlighted
Super User
Super User

Re: Extract part of a dynamic content value

@Anonymous Great to hear!  One thing I was thinking about this morning is that the end result may still be an 'array' (even though there is only one thing in it).  If you run into any trouble where your future steps either throw an error, OR try to kick off an Apply to Each loop when you try to use the first name, try wrapping the expression with a String(), like this:

 

string(split(split(triggerBody()['text'],'@')[0],'.')[0])

This should take the previous result and convert it to a string value, which should avoid all the yuck suggested above.

 

Good luck!

-Ed-

Highlighted
Anonymous
Not applicable

Re: Extract part of a dynamic content value

No issues with it being an array but good idea.

 

On the thought of arrays there are other dynamic content objects (is the the proper term?) that I want to put in tot he body of my email but it always adds a Apply to Each and I get mulitple emails and not the desired outcome.

 

1. I havent been abel to find any good doco (notihng new microsoft) to tell me what an array  and whats a string.  Is there a way to tell?

 

2. How can I add the arrays to the email body without the pesky Apply to Each?  Do I just convert it to a string like you did above and then add it?

Highlighted
Super User
Super User

Re: Extract part of a dynamic content value

So, I think of it in these terms - If a field (Dynamic Value) has the capability to hold more than one piece of information, then there's a good chance it's going to be an array.  If you look at the previous runs in Flow, and specifically the output of the step that has the information you want, you should see the JSON which will include the "Type:" for the field.

 

To alleviate unwanted Apply to Each loops, look at the First() function which sort of tricks Flow into thinking you only want the first element of the array.  Lots of good documentation out there, but this post does a pretty good job explaining a couple of methods.

 

Have fun!

-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.

Helpful resources

Announcements
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (10,307)