cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
gunnahafta
Level: Powered On

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
Super User
Super User

Re: Extract part of a dynamic content value

@gunnahafta 

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
Super User
Super User

Re: Extract part of a dynamic content value

@gunnahafta 

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

gunnahafta
Level: Powered On

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.

Super User
Super User

Re: Extract part of a dynamic content value

@gunnahafta 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-

gunnahafta
Level: Powered On

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?

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
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 394 members 6,673 guests
Please welcome our newest community members: