cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
drfixer
Helper I
Helper I

how to check existence of JSON value when it only appears when a value is present

Dear PA community,

 

I'm pulling data from an HR system. We have miscellaneous fields we use to track flags, shirt sizes, etc.

 

The problem is these fields ONLY appear in the JSON download when they are populated, otherwise there's no data, no JSON.

 

I have a condition to check for ALL miscfields as NULL; however, I now need to test for welcomeSNT flag.  It worked when I only used that field but I added Shirt Size which is populated upon hire, thus miscFields will never be NULL.

 

My original condition was but this just checked if ANY fields existed:

 

body('Parse_JSON_-_Individual_Employee')?['miscFields'] = NULL

 

 

Here is the JSON that comes down when it has values:

 

 "miscFields": [
    {
      "title": "Shirt Size",
      "value": "4"
    },
    {
      "title": "welcomeSNT",
      "value": "True"
    },
    {
      "title": "welcomeDTE",
      "value": "12/1/2020 12:00 AM"
    }
]

 

 

Any recommendations for how to check if "welcomeSNT" exists even when NO DATA will come across unless it is TRUE?

1 ACCEPTED SOLUTION

Accepted Solutions
ccc333ab
Solution Sage
Solution Sage

Here is one approach. 

 

1. Just setting up your data in a COMPOSE. Of course you'll need to adjust to use your dynamic content that corresponds to your data. 

ccc333ab_0-1627154119374.png

 

2. Creating a variable to track if the flag is set or not. 

ccc333ab_1-1627154151590.png

 

3. Now creating a COMPOSE statement to only pull in the miscFields data. 

ccc333ab_2-1627154186987.png

4. Now looping through each miscField, and check if the current Title is welcomeSNT and if so, is the flag set to TRUE. If so then set the variable flag we initialized to TRUE. 

ccc333ab_3-1627154277185.png

In the Condition, the two expressions are: 

items('Apply_to_each')?['Title']  (equal to welcomeSNT)

items('Apply_to_each')?['value']   (equal to True)

 

5. And now outside this loop, you can then check to see if the WelcomeSNTFLag is true and do whatever it is you need to do. 

 

View solution in original post

4 REPLIES 4
ccc333ab
Solution Sage
Solution Sage

Here is one approach. 

 

1. Just setting up your data in a COMPOSE. Of course you'll need to adjust to use your dynamic content that corresponds to your data. 

ccc333ab_0-1627154119374.png

 

2. Creating a variable to track if the flag is set or not. 

ccc333ab_1-1627154151590.png

 

3. Now creating a COMPOSE statement to only pull in the miscFields data. 

ccc333ab_2-1627154186987.png

4. Now looping through each miscField, and check if the current Title is welcomeSNT and if so, is the flag set to TRUE. If so then set the variable flag we initialized to TRUE. 

ccc333ab_3-1627154277185.png

In the Condition, the two expressions are: 

items('Apply_to_each')?['Title']  (equal to welcomeSNT)

items('Apply_to_each')?['value']   (equal to True)

 

5. And now outside this loop, you can then check to see if the WelcomeSNTFLag is true and do whatever it is you need to do. 

 

View solution in original post

Hi @drfixer 

 

Just for the mix, here is a method using a filter array.  

 

DamoBird365_0-1627155453027.png

 

If you needed to ensure that the value is true also, you can concat both values as follows and create a concatenated string:

 

DamoBird365_1-1627155581483.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

 

drfixer
Helper I
Helper I

Thank you for your proposed ideas...

 

When I tried to create the compose, it threw the following error because there's no data there for this particular employee.

 

drfixer_0-1627169604944.png

 

Error

InvalidTemplate. Unable to process template language expressions in action 'Compose-miscFields' inputs at line '1' and column '12315': 'The template language expression 'body('Parse_JSON_-_Individual_Employee')?['miscFields'][1]?['value']' cannot be evaluated because array index '1' is outside bounds (0, 0) of array. Please see https://aka.ms/logicexpressions for usage details.'.

 

On your 2nd solution, I could just search the body of the JSON and search for the text; however, I'd like the solution to be more whereby I can access data IF it shows

drfixer
Helper I
Helper I

@ccc333ab Thank you - I figured it out...

 

1. Did a compose on the BODY of the JSON

2. Another compose to isolate the miscFields objects as outputs('Compose-miscFields')?['miscFields']

3. Apply_to_each against Compose in #2

4. Parsed JSON on Current Item under #3

5. Compose to get item but will use a variable to get the data. I suppose I could use a SWITCH for each item I am trying to capture

 

Thank you so much!

 

drfixer_1-1627174253365.png

 

 

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (2,522)