Hi,
I'm trying to build a flow that runs based on a choice field in a sharepoint list;
I have a choice fields with 4 choices lets say:
-green
-red
-yellow
-black
I want to be able to send an email based on these fields, but the catch here I want to avoid using a switch, but a kind of a map telling the flow that
green = green@email
red = red@email
and than use the result further on.
Is this possible?
Solved! Go to Solution.
Hi @nikola_bgd,
Yes, that would be possible.
I would compose an array and filter that. But there are probably other approaches as well.
Below is an example of that approach.
1. Add a compose with the following content
[
{
"Color": "Green",
"Email": "green@contoso.onmicrosoft.com"
},
{
"Color": "Red",
"Email": "red@contoso.onmicrosoft.com"
},
{
"Color": "Yellow",
"Email": "yellow@contoso.onmicrosoft.com"
},
{
"Color": "Black",
"Email": "black@contoso.onmicrosoft.com"
}
]
2. Add a parse json action with the following schema
{
"type": "array",
"items": {
"type": "object",
"properties": {
"Color": {
"type": "string"
},
"Email": {
"type": "string"
}
},
"required": [
"Color",
"Email"
]
}
}
3. Add a filter array. Configure it to filter it based on the color from your SharePoint list
4. Use the email value from the filtered array to send an email to the correct address. In the example below I am using this expression
body('Filter_array')?[0]?['Email']
Hi @nikola_bgd,
Yes, that would be possible.
I would compose an array and filter that. But there are probably other approaches as well.
Below is an example of that approach.
1. Add a compose with the following content
[
{
"Color": "Green",
"Email": "green@contoso.onmicrosoft.com"
},
{
"Color": "Red",
"Email": "red@contoso.onmicrosoft.com"
},
{
"Color": "Yellow",
"Email": "yellow@contoso.onmicrosoft.com"
},
{
"Color": "Black",
"Email": "black@contoso.onmicrosoft.com"
}
]
2. Add a parse json action with the following schema
{
"type": "array",
"items": {
"type": "object",
"properties": {
"Color": {
"type": "string"
},
"Email": {
"type": "string"
}
},
"required": [
"Color",
"Email"
]
}
}
3. Add a filter array. Configure it to filter it based on the color from your SharePoint list
4. Use the email value from the filtered array to send an email to the correct address. In the example below I am using this expression
body('Filter_array')?[0]?['Email']
@nikola_bgd you can do as follows:
1. Use initialize variable, and name it as emailaddress of type string
2. Use Set Variable action with following expression, replace 'Status/Value' with your columnname/value.
if(equals(items('Apply_to_each_6')?['Status/Value'],'green'),'green@test.com', if(equals(items('Apply_to_each_6')?['Status/Value'],'red'),'red@test.com','othercolor@test.com'))
3. Then you can use value of variable directly in send email action
Yes, it is possible. You would need a compose step with a JSON array like this:
[
{
"colour": "green",
"email": "green@somedomain.com"
},
{
"colour": "red",
"email": "red@somedomain.com"
},
{
"colour": "yello",
"email": "yello@somedomain.com"
},
{
"colour": "black",
"email": "black@somedomain.com"
}
]
You can then filter this array based on your field value and collect the email address in the matching result. This would be the method I would use, but there are other ways also.
This is also quite a tidy method:
concat(
if(equals(outputs('colour'), 'green'), 'green@email.com', ''),
if(equals(outputs('colour'), 'red'), 'red@email.com', ''),
if(equals(outputs('colour'), 'yellow'), 'yellow@email.com', ''),
if(equals(outputs('colour'), 'black'), 'black@email.com', '')
)
you would need to replace outputs('colour') with your field value.
I get an error with this one:
Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The repetition action(s) 'Apply_to_each_6' referenced by 'inputs' in action 'Set_variable' are not defined in the template
@nikola_bgd , it looks like you are using something in your expression that is not part of your flow, can you provide screenshot of the flow and expression that you are using, so that i can point out whats wrong.
Hi,
I think your suggestion has an apply to each which is not present in a simple expresion that I'm trying to build. I'm actually trying to avoid an apply to each, this was your expresion:
if(equals(items('Apply_to_each_6')?['Status/Value'],'green'),'green@test.com', if(equals(items('Apply_to_each_6')?['Status/Value'],'red'),'red@test.com','othercolor@test.com'))
@nikola_bgd Apply to each is there to get value of the status column from the Item, how you are getting the data from SharePoint List? Are you using Get Items action or getting data from trigger? It would be helpful if you can share screenshot of your flow.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
Read the latest about new experiences and capabilities in the Power Automate product blog.
If you are a small business ISV/Reseller, share your thoughts with our research team.
User | Count |
---|---|
26 | |
25 | |
23 | |
23 | |
14 |
User | Count |
---|---|
46 | |
33 | |
32 | |
31 | |
30 |