cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nikola_bgd
Advocate II
Advocate II

Sharepoint choice field mapping

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?

8 REPLIES 8
Expiscornovus
Super User II
Super User II

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"
  }
]

compose_colors.png

 

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"
        ]
    }
}

parsejson_colors.png

 

3. Add a filter array. Configure it to filter it based on the color from your SharePoint list

filterarray_colors.png

 

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']

 

sendtocolors.png

 

annajhaveri
Super User
Super User

@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 

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.
Paulie78
Super User III
Super User III

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.

Paulie78
Super User III
Super User III

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.

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

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.

Regards,
Anna Jhaveri

If I have answered your question, please mark the post as Solved to help other users to identify the correct answer
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (15,708)