Select to view content in your preferred language

Dynamically extracting a coded value from a coded value domain

61
0
Friday
TylerGraham2
Frequent Contributor

I was trying to use Power Automate to generate automated emails when a Survey was submitted that was missing data when certain conditions were met.  One issue I had was getting the project name into the email.  The project name field is a coded value domain and it would only give the code and not the value in the email, which isn't very useful to most people. 

I hadn't seen any solutions for dynamically pulling values from a coded value domain using Power Automate that didn't involve creating a new field in the feature layer and populating that field with the value and then calling the field in Power Automate. My issue was the CVD values are buried a couple levels deep in a JSON and I had a real hard time figuring out how to access them.  The get coded value domains from feature layer can output a specific cvd list, but Power Automate did want to recognize it as a valid json format in later steps.    

Here's my workflow. This uses the premium level ArcGIS connection. I used the When a Survey Response is Submitted as the trigger and the "Get Coded Value Domains from Feature Layer as an action. I then added the Initialize Variable action with the type set to String and value dynamic content pointing to the Project Name field from When a Survey Response is Submitted. I gave the variable a name of Project Value, which is what you will look for in Dynamic Content later on.  

At this point save and run a test. In the test results go to the Get Coded Value Domains from Feature Layer, click Show Raw Outputs, and then copy and paste the raw output into a parse json viewer.  I used this one https://jsonviewer.stack.hu/ You can view it as text or use the Viewer tab to see the schema of the json in an expandable structure view to understand how everything is nested. In my instance I am looking for the "projname" domain and the "codes" under that.  Codes puts the cvd code first and then the value it is formatted like "test1234": "Test Project".  Names flips that and puts the value first and then the cvd code so you would get "Test Project": "test1234". It is important to use the Codes because the name:value pairing of the json 

My next action to add is Parse JSON. For the content I will use the Body dynamic content from Get Coded Value Domains from Feature Layer and then to get down to the specific cvd I want I need to add a little bit extra to it. To drill down a level in the json you need to add the name of the level in square brackets and apostrophes to the end of the dynamic content. You add another one for the next level.  So to get to the codes of my projname cvd the content of the Parse JSON action looks like this:   

body('Get_coded_value_domains_from_feature_layer')['projname']['codes']
 
For the schema, click the Use Sample Payload to Generate Schema and paste the raw output copied earlier into the popup window. This will drill down and returns the project name cvd with the codes in the name position of the json and the cvd values in the value position of the json, again, like looking like this  "test1234": "Test Project"
 
The next action to add is Compose, which is where we will use the variable we set earlier to filter the body output from the Parse JSON.  In the Inputs click fx to insert an expression, then click the Dynamic Content tab in the popup window.  From Parse JSON add the Body, then add square brackets to the end and in between the brackets add the Project Value created by the Initialize Variable.  The expression will look like this: 
 
body('Parse_JSON')[variables('Project Value')]
 
Since we drilled down through the JSON to the cvd with the code:value as the name:value JSON format the [variables('Project Value')] is taking us down the last step and asking for the value of a name that matches the Project Value variable.  Since we assigned the Project Value to the Project Name field from the "When a survey response is submitted" action this asking for the specific value that matches the code from the record that was submitted.  
 
When I use the Compose output elsewhere in the flow I will now get "Test Project" instead of "test1234".
0 Kudos
0 Replies