When If Statement is False Keep Existing Value

429
1
08-02-2018 02:58 PM
BrianShepard
Occasional Contributor

The background gets pretty involved, but I can provide more information if it's helpful.  What I'm trying to do is:

Set the value of a hidden (bind::type = integer) question if a condition is met, and if the condition is not met keep it's existing value.

We have several QR Codes, each one representing a unique URL.  I want to know how many QR codes have been scanned during a survey.  A barcode question populates ${QrCode} when it's scanned.  I have a hidden (bind::type = integer) question specific to each unique URL that is defaulted to 0.  If ${QrCode} = one of the URLs, the specific question related to that URL should change from 0 to 1.  That works fine, but if another URL is scanned the previous question whose value changed to 1 changes back to 0.  Is there a way to have a question default to 0, change to 1 upon a certain condition, and then remain that value?

Barcode question populates ${QrCode} with a URL

Hidden integer question (${QrCodeVisit1}) defaults to 0, calculation is: if(${QrCode}="URL1",1,0)

If ${QrCode} = "URL1", then ${QrCodeVisit1} = 1

If another barcode is scanned and ${QrCode} = "URL2", then ${QrCodeVisit1} reverts to 0.  I'd like that 1 to persist.

I tried if(${QrCode}="URL1",1,${QrCodeVisit1}), but I get an error.  Is there any way to specify the result of an if statement to just not do anything?

I'm not totally positive my grand plan is going to work out, but if I get this resolved I'll be a little further down the path.

0 Kudos
1 Reply
JamesTedrick
Esri Esteemed Contributor

Hi Brian,

Depending on the range of values that could be calculated, you might want to include a self-check in the if statement sequence:

if (. != 0, ., <insert URL lookup if sequence>)

This would first check to see if the value has been moved off of the default; if it has, it would retain the existing value; otherwise perform the URL lookup/assignment.

Unfortunately, this causes a circular reference in form validation so it does not work.

0 Kudos