cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

not sure how to handle JSON where contents might be object or empty string

Receiving the following error when trying to reference json array apply_to_each item:

 

InvalidTemplate. Unable to process template language expressions in action 'Append_to_string_variable' inputs at line '1' and column '2832': 'The template language expression 'if(empty(items('Apply_to_each')?['blah_product']?['display_value']),'',items('Apply_to_each')?['blah_product']?['display_value'])' cannot be evaluated because property 'display_value' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

 

I've struggled to get it to the point where I could reference the json results array at all, but finally got it this far by allowing the schema to define "blah_product" as either an object, with a property of 'display_value', or a string.  In general the vast majority of results for this field come over with "blah_product":{"display_value":"whatever","link":"some_link"}, but in the dataset I'm receiving, if the value from the source is blank, I'll receive "blah_product":"".  

 

As mentioned, in the schema, without allowing both types, it fails before this point, but now I'm struggling trying to include the results as dynamic content or an expression.  the "blah_product" doesn't actually show up as dynamic content, but it works to refer to it as items('Apply_to_each')?['blah_product']?['display_value'], but in my for/each, it fails when it's a string (which makes sense, since I'm referring to an object property) but I can't figure out how to say 'if this object property exists, then use it, otherwise use a blank value'.  The if() and empty() are just my latest attempts, but it seems referring to the property at all fails the entire entry.

 

My next thought is to put it in a conditional expression, though i have 4 fields like this and not really looking forward to building multiple conditions and multiple variables if there is an expression I could use, especially since it already takes 7 minutes just to go through a few hundred lines, and I'll have several thousand lines to go through for the complete dataset.  Not entirely sure how long it will take if I have to add multiple conditional tests for every record.  if there was something like 'property_exists()' or something that was allowed to at least look for it and then fail, then i assume the if block would work?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Regular Visitor

I was able to resolve this a couple ways, both required me to test the entry as a string first instead of testing for the property.  Seems when testing it as a string, it considers the entire {"stuff":"text","otherstuff":"othertext"} object as the string, so if i tested:

 

items('Apply_to_each')?['blah_product'] equal to "", it was ok performing the test, and gave me true if the json was  

     "blah_product":""

and false if the json was :

     "blah_product":{"display_value":"whatever","link":"some_link"}

 

Then when the result was true, I could give it a blank entry, and when it was false I could refer to the object:property without it failing, because it obviously doesn't look inside the if/false clause to try testing if the false condition would have been possible.

 

I initially put this all in multiple condition blocks, but once I got it working this way, I was able to convert it back to if() expressions which seem preferrable, because all those condition blocks on even a smallish subset of my data took nearly an hour to run, where the if() expressions run my entire data set in minutes.

 

Also, in case someone else runs into this, or it's me looking for this problem a year from now and I've forgotten already, the if() requires an equals() expression, not if(x='',....) since it expressions don't recognize the = sign.

View solution in original post

Highlighted

Hi @dnickelson,

 

Thanks for your solution sharing, for more clear to explain your solution, I give an example of your expression to other user could understand it more:

 

eqauls(items('Apply_to_each')?['blah_product'],'')

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Regular Visitor

I was able to resolve this a couple ways, both required me to test the entry as a string first instead of testing for the property.  Seems when testing it as a string, it considers the entire {"stuff":"text","otherstuff":"othertext"} object as the string, so if i tested:

 

items('Apply_to_each')?['blah_product'] equal to "", it was ok performing the test, and gave me true if the json was  

     "blah_product":""

and false if the json was :

     "blah_product":{"display_value":"whatever","link":"some_link"}

 

Then when the result was true, I could give it a blank entry, and when it was false I could refer to the object:property without it failing, because it obviously doesn't look inside the if/false clause to try testing if the false condition would have been possible.

 

I initially put this all in multiple condition blocks, but once I got it working this way, I was able to convert it back to if() expressions which seem preferrable, because all those condition blocks on even a smallish subset of my data took nearly an hour to run, where the if() expressions run my entire data set in minutes.

 

Also, in case someone else runs into this, or it's me looking for this problem a year from now and I've forgotten already, the if() requires an equals() expression, not if(x='',....) since it expressions don't recognize the = sign.

View solution in original post

Highlighted

Hi @dnickelson,

 

Thanks for your solution sharing, for more clear to explain your solution, I give an example of your expression to other user could understand it more:

 

eqauls(items('Apply_to_each')?['blah_product'],'')

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (16,399)