Select to view content in your preferred language

Help with constraints for data validation

284
6
03-20-2025 12:43 PM
ZoieLowery
Emerging Contributor

Hi there.

How can I create a constraint that will pull from previous survey entries and compare the values to what the user enters?

I need help with a survey I am creating for utility meter readings. I have the survey successfully created using a feature layer and related table in Survey123 Connect. The meter data is stored in the Meters point layer, and associated readings are stored in the Meter Readings related table.

My problem is that the end user has asked for a way to validate/QAQC the meter reading entries. The goal is for a user to input a meter reading, and have that entry compared to previous entries for that meter. A new reading should always be greater in value than previous readings. 

Each meter has a GlobalID that links it to the related table and a serial number that separates it from other meters. 

 

Any help is very appreciated!!

 

0 Kudos
6 Replies
DavidSolari
MVP Regular Contributor

You can combine the pulldata("@layer") function with some additional URL parameters such as orderByFields to sort the results appropriately. That way the data you pull (which is the first record returned by the query) will have the previous results, which you can extract with further pulldata calls and stuff into your comparison functions.

0 Kudos
ZoieLowery
Emerging Contributor

Okay, that's kind of what I was thinking. Do I need to store the pulldata function in its own question/field before calling it's return value in the constraint of the Meter Reading entry? and if so, what kind of question should I use for that, calculate?

In tother words, can I pulldata() directly in the Meter Reading question and have it compare to the users entry all in one question, or are more steps/questions required?

0 Kudos
DavidSolari
MVP Regular Contributor

If you're validating more than one survey question you'll want to store the pulldata results in a hidden question, then extract answers from the JSON object it returns in your "constraint" column, something like:

. >= pulldata("@json", ${previous_survey}, "attributes.meter_level")

Or whatever your field names are, you get the idea.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Always put pulldata in its own field then use that field otherwise it does not run correctly.  Many posts on this.

0 Kudos
ZoieLowery
Emerging Contributor

Alright. This was my attempt at writing the calculation for pulling the last reading.

pulldata('@layer', 'getRecord', 'attributes.Reading', 'https://um-facilities.maps.arcgis.com/home/item.html?id=a160d81f924545f4a563527c858bde0&sublayer=4')

Using this formula:
'pulldata("@layer", "getValue", "<JSON property>", "<URL>", "<WHERE clause>")
I don't know what the WHERE clause should be. What I want is for it to pull the latest inputted reading value for a given serial number. The serial number is autopopulating from the point they click in field maps that brings them to the survey.

0 Kudos
ZoieLowery
Emerging Contributor

Alright. This was my attempt at writing the calculation for pulling the last reading.

pulldata('@layer', 'getRecord', 'attributes.Reading', 'https://um-facilities.maps.arcgis.com/home/item.html?id=a160d81f924545f4a563527c858bde0&sublayer=4')

Using this formula:
'pulldata("@layer", "getValue", "<JSON property>", "<URL>", "<WHERE clause>")
I don't know what the WHERE clause should be. What I want is for it to pull the latest inputted reading value for a given serial number. The serial number is autopopulating from the point they click in field maps that brings them to the survey.

0 Kudos