Hey kids! So I’ve recently been asked to create an automated flow using Microsoft Flow (Power Automate) that is attached to Azure DevOps. We want to send a confirmation email to the person who created the work item.
You would think this would not be hard.
I searched for days on how to do this another way but was unable to figure it out without using a ridiculous process. So! In case others are in the same boat - here are the steps to get the email address from any of the Identity fields in an Azure DevOps work item.
The CreatedBy object looks like : "UserFirst UserLast <firstname.lastname@example.org>"
So we have to strip the text name and carrots. In C#, this is super-duper easy!!
var strippedName = name.Substring(name.IndexOf('<') + 1, name.Length - 1);
Not so in this program. Boooooooooo :(
First, you do need to have the upgraded version of Flow (Power Automate). We’ll refer to it as Flow from now on.
Step 1 - Create a new automated flow
During this step, you’ll be able to connect your Azure DevOps instance to your Flow account for dynamic usage.
Step 2 - Add the “When a new work item is created” task
Fill in the project and other details. This is another place I couldn’t find a way to use a flow universally for all projects. If anyone knows of a way, please shoot me a message or add to the comments!
Step 3 - Add “initialize variable"
Add a variable for the index of the opening carrot (<)
Add a variable for the index of the closing carrot (>)
Add a variable for the email string coming from Azure DevOps
Add a variable for the length
Add a variable to trim the opening carrot (<)
Add a variable to trim the last char
Step 4 - Add "Set variable"
We want to get the value of the system object "CreatedBy". This variable will set the index of the first carrot
The next variable sets the index of the closing carrot
Then we set the email length
Next we subtract 1 from the length
Next, we set the index of the open carrot, adding 1 to it so it strips out the carrot itself
Finally we put all the pieces together to get just the email from the system object CreatedBy
That is a ridiculous amount of steps to get an email. Way. Too. Many. Are you listening, Microsoft?? If they had customer service or read any of the community ideas, I'd probably complain.
Anyways, I hope this post can help someone else who may be on the struggle bus. I'm sure there are faster ways with less variables to do this - but I was just irritated, so I didn't refactor (I know, rookie move). The people that will maintain this flow are not developers so I tried to make it easy for them to follow. They get it, so I'm alright with that
Bonus thing I found:
It took me quite a few tries to figure out what to compare using custom fields from my Azure DevOps work items. So as a bonus, here is a quick way to compare if you need to check against 'selected value' in a list.
Include your condition and open the Expression section. Find the name of your custom object and replace what I have below. I'm checking to see if my custom field "Request Type" is equal to "Test"