Amey Holden

View Original

Mapping Option Sets/Choice Labels from Dynamics 365 Marketing Form Submissions to Custom Tables with Power Automate

Following on from a previous post “Mapping Dynamics 365 Marketing Form Submissions to Custom Tables with Power Automate“, I covered option sets, but only how to get the value of the option set/choice e.g. 100006, not the actual label ‘Vegemite’. I used a previous blog post of mine “Set Dataverse Choices in Power Automate dynamically - without a switch statement!“ and kind of reverse engineered it. Rather than using the label to find the value, we are going to use the value to find the label, and then add it on to the form submission response string for parsing later.

PS fluffy intro and background reading is in this post, no socks will be put on centipedes here - I also realised I could strip out a lot of extra unnecessary actions from the previous method which is soooooo satisfying!

TLDR: skip to ‘Option Set Labels Please‘

See this content in the original post
See this content in the original post

Skip the blank responses

Lets ensure we only ‘handle’ the fields that have a response captured, because if its blank it will cause our flow to fail and not all fields on the form will always be mandatory. Add a condition step that checks if the ‘Field Value’ is blank, if its blank we will simply append the Field Name and Field Value as a key value pair to our ‘Response String’ which will show that there was no data provided.

See this content in the original post

Switch it up

In the ‘No’ branch of your condition action, create a switch statement based on the ‘Marketing Form Field Type’, but just in case this comes back blank, lets make sure our Switch doesn’t cry (fail) by using coalesce and defaulting the value to ‘NULL’ so that the default action will proceed. Then add a case for Lookup (11) and Option Set Choice (3). Previous post covers what you need for Lookup so lets go get the Option Set magic.

See this content in the original post

Default the Default

In the Default case of the switch, add an action ‘Append to String Variable’ which appends the Field name and value as a key value pair, this is perfect for most other field types such as text, numbers and dates.

Option Set Labels Please

Five magic steps to turn a humble yet meaningless integer into a word that actually means something. It could technically be 3 steps by creating the TableLogicalName and FieldLogicalName directly in the Invoke an HTTP request action, but I’m not here to show off and boggle your brain too much, so I won’t 😉

See this content in the original post

STEP 3: Find the option set ‘metadata’

The answer to translating the integer ‘15’ into a label ‘Equipment Rental and Leasing’ is hidden deep in a land far far away called ‘Metadata’. Don’t be scared, just read my other blog post for more details if you get stuck! Add a ‘Invoke a HTTP request’ action, Method: GET and URL of the request is pasted below. You can see we are using the FieldLogicalName and TableLogicalName outputs in here, plus URIHost to determine the URL of the dynamics/power platform instance you are working in e.g. ameyholden.crm6.dynamics.com.

See this content in the original post

STEP 4: Filter the metadata

The previous action returns all the metadata for the field, so all the possible options in the option set have come back. Add a Filter Array action, then using the body() condition below we can pass in just the Option Set ‘Options’ rather than the full output from the previous step (note this will not be available as an item to select from the ‘Dynamic Content’ picker but I promise the expression works. The filter is just looking to find a match for the option set value in the metadata, using the number we got back in the marketing for submission ‘15’.

See this content in the original post

STEP 5: Append, Append, Append!

The option set label value is at your fingertips. Append to your existing string variable as below. The field name value here is optional, useful for mapping to create records later in your flow but in the case of showing the user the human readable version the ‘Label-UserLocalizedLabel-Label Label Label Label Label Label is the one you want.

See this content in the original post

Now what?

Jump back in to my last post at ‘Parse the Submitted Values’ to continue through the mapping and record updating things, maybe set up a nice note to add to the timeline that shows the form response summary in a human readable way, or maybe just give yourself a pat on the back and call it a day. You do you.