Select to view content in your preferred language

Conditional Calculation with pulldata @layer

325
4
Jump to solution
04-03-2024 01:01 PM
ZachBodenner
MVP Regular Contributor

Hello, 

I am trying to do some conditional calculating. I have an address field in my survey and I'm using pulldata @layer to get the address of a parcel that the point is placed on. 

If the point is not placed on a parcel, I'd like to return a piece of text like "No Address Found" or something. 

My actual pulldata is working fine, I get addresses when the point is on a parcel, but I want to set a default value. From what I understand, actually using Default might not work because that only evaluates when the survey is opened, so if I click a point that isn't on an address, then the default is overwritten with nothing.

pulldata("@layer", "getValueAt", "attributes.ADDRESS", "<parcel REST endpoint>", ${EP311_point})

0 Kudos
1 Solution

Accepted Solutions
DuncanC
Occasional Contributor

The example for if is:

if(selected(${question_one}, 'yes') and selected(${question_two}, 'yes'), 'yes', 'no')

So you'd want something like

if($raw='', 'No Address Found', $raw)

Or to smash it all together:
if(pulldata("@layer", "getValueAt", "attributes.ADDRESS", "<parcel REST endpoint>", ${EP311_point})='', 'No Address Found', pulldata("@layer", "getValueAt", "attributes.ADDRESS", "<parcel REST endpoint>", ${EP311_point}))

Yuck.  You come back to that in 6 months there is nothing you can do with it but pull it apart.  That's a pain.  Do future you a solid and try out the extra lines.  

Also yeah, I do not like the XLSforms syntax, don't end up using it quite enough to ever fully feel comfortable with it,  won't surprise me if it needs a little tweaking to work.

View solution in original post

0 Kudos
4 Replies
DuncanC
Occasional Contributor

Break it out into two lines?  Stash your pulldata result in a hidden question.  Set the default to the same "" you get when it fails to return.  Then on the next line, the address your going to display just use a if to look at that hidden.

Pretty sure you could also just nest your pulldata into the if but I like the readablity of more lines.

 

0 Kudos
ZachBodenner
MVP Regular Contributor

Ideally I'd avoid extra lines though I had thought of that option too - do you have an example of the nested If syntax? The Survey123 connect syntax turns me around sometimes.

0 Kudos
DuncanC
Occasional Contributor

The example for if is:

if(selected(${question_one}, 'yes') and selected(${question_two}, 'yes'), 'yes', 'no')

So you'd want something like

if($raw='', 'No Address Found', $raw)

Or to smash it all together:
if(pulldata("@layer", "getValueAt", "attributes.ADDRESS", "<parcel REST endpoint>", ${EP311_point})='', 'No Address Found', pulldata("@layer", "getValueAt", "attributes.ADDRESS", "<parcel REST endpoint>", ${EP311_point}))

Yuck.  You come back to that in 6 months there is nothing you can do with it but pull it apart.  That's a pain.  Do future you a solid and try out the extra lines.  

Also yeah, I do not like the XLSforms syntax, don't end up using it quite enough to ever fully feel comfortable with it,  won't surprise me if it needs a little tweaking to work.

0 Kudos
ZachBodenner
MVP Regular Contributor

Yes, that is indeed cumbersome but with one minor tweak it does in fact work:

if(string-length(pulldata("@layer", "getValueAt", "attributes.ADDRESS", "https://gis.edenprairie.org/maps/rest/services/Public/Parcels/MapServer/0", ${EP311_point})>0),'No Address Found',pulldata("@layer", "getValueAt", "attributes.ADDRESS", "https://gis.edenprairie.org/maps/rest/services/Public/Parcels/MapServer/0", ${EP311_point}))

For some reason the empty quotes didn't get it done, but comparing against the return string length did the trick.