Select to view content in your preferred language

Survey123 get Inbox value or calculate something else

145
4
Jump to solution
02-11-2025 01:43 AM
ECarson
Occasional Contributor

Hi,

I'm trying to populate a field ${DEVICE_ID} with either the corresponding Inbox value or a calculated value for a new record?

The new ${DEVICE_ID} value is calculated from a barcode scan. pulldata("@javascript", "split_barcode_string.js", "getIDFromDeviceStringAndGivenIndex", ${DEVICE_SCAN},":",3)

I've tried and if statement but not sure how you can reference an Inbox variable, any ideas?

if(${survey_mode}='new',${DEVICE_ID_NEW},<Inbox Device ID Variable>)

Thanks for any suggestions.

 

0 Kudos
1 Solution

Accepted Solutions
abureaux
MVP Frequent Contributor

A single form in S123 shouldn't be an issue. I have a very similar workflow, but I built the app in PowerApps. I do have something similarish in S123 though.

I wouldn't necessarily use the Inbox though. All you need is a bar-code scanner (obviously) and pulldata(). Here are the three workflows I'd see working in a single form (if you wanted to use the inbox):

  • For a new item, you'd scan the barcode, extract the value, enter data into the empty fields, and submit.
  • For an existing item, two options
    • You can click "Collect", and use the bar-code scanner. That will get your value, and a pulldata() will search your Feature Layer for that value. If it is located, more pulldata() fields will fill in all available data. If not, see the first bullet point.
    • You can click "Inbox" and search by ${DEVICE_ID}. Open the item that way, and everything is filled in for you (no scan necessary).

I use something similar in S123 with project numbers. When a project number is located, pulldata() extracts all the required fields from the FL.

Survey123 Tricks of the Trade: pulldata("@layer")

View solution in original post

0 Kudos
4 Replies
abureaux
MVP Frequent Contributor

Honestly, not entirely sure what you mean. The workflow is missing a couple steps for me. But I will take a guess though...

  • You have a field called [DEVICE_ID_NEW].
  • When a new survey is started, your user enters [DEVICE_ID_NEW].
  • When the survey is anytime thereafter, that field is hidden, and a barcode scanner is in it's place. The user is then required to scan a barcode.

Does that sound about right? In that case, where they are two different fields and only one should have data at one time, I would use a calculate (as you mentioned), but would use coalesce() rather than if(). Coalesce() is similar to an if() in this case, but takes far less effort. Coalesce() takes the first non-null value. E.g.,

coalesce(${field_1},${field_2})

The result will be either field_1 or field_2. It will take whichever value isn't null first, starting from the left.

There is no reason this shouldn't work with your survey or the inbox (same with the if() statement, honestly).

If you are still having trouble, uploading your XLSX would help.

0 Kudos
ECarson
Occasional Contributor

Thanks for the response, after rereading my post I believe that I haven't made it very clear.

  • Action for a new record the user scans a barcode, there's a calculation preformed, and an Id is extracted and is the ${device_id} variable.
  • Action to update a record requires the user to go to the inbox and scan the barcode to extract the record associated to the Id and returns the id and assigns it to ${device_id} in the survey form.

Each action above can be completed in their own survey123 form, but I don't see how the two actions can be combined into a single form.

As I understand it for the inbox to populate the field eg ${device_id} I can't have the pulldata call there. Using the coalesce(<Inbox Device ID Variable>,pulldata("@javascript", "split_barcode_string.js", "getIDFromDeviceStringAndGivenIndex", ${DEVICE_SCAN},":",3)) or an if statement I can't see how to distinguish between the new record calculation, or an inbox supplied variable.

 

 

0 Kudos
abureaux
MVP Frequent Contributor

A single form in S123 shouldn't be an issue. I have a very similar workflow, but I built the app in PowerApps. I do have something similarish in S123 though.

I wouldn't necessarily use the Inbox though. All you need is a bar-code scanner (obviously) and pulldata(). Here are the three workflows I'd see working in a single form (if you wanted to use the inbox):

  • For a new item, you'd scan the barcode, extract the value, enter data into the empty fields, and submit.
  • For an existing item, two options
    • You can click "Collect", and use the bar-code scanner. That will get your value, and a pulldata() will search your Feature Layer for that value. If it is located, more pulldata() fields will fill in all available data. If not, see the first bullet point.
    • You can click "Inbox" and search by ${DEVICE_ID}. Open the item that way, and everything is filled in for you (no scan necessary).

I use something similar in S123 with project numbers. When a project number is located, pulldata() extracts all the required fields from the FL.

Survey123 Tricks of the Trade: pulldata("@layer")

0 Kudos
ECarson
Occasional Contributor

Thank Abureaux, for your responses.

Although I haven't implemented your solution I do believe it should work.

After discussion with the customer they want the ability to add new records and update records as separate apps. As almost all records are currently in the database.

Regards,

Elliott

0 Kudos