Arcade Expression for Barcode Scanning

4027
43
Jump to solution
05-25-2022 06:47 AM
JD1016
by
Occasional Contributor III

Hello Everyone,

I need some assistance with code creation whereby after I scan my barcode it will auto-populate another question on the form pertaining to "address".  The calculated expressions are being applied in ArcGIS Field Maps within the Form.  Please see code attached at the bottom of this posting.

I was first able to obtain some helpful code examples via github but I am definitely missing something.  The examples on github center around extracting certain components from the barcode and converting them to descriptions versus the numeric code.  For my situation, the entire barcode is equivalent to the address whereby each barcode is uniquely assigned to this address information.

My workflow for this is as such...I scan the barcode, it populates the "OldMeterNumber" field with 1NF314421199 and in turn populates my "Address" field with 69944 SUNNYFIELD RD.

At this point, it keeps coming up "Unknown".

Thank you for taking the time and assisting.

Jeff

var BARCODE = $feature.OldMeterNumber
var address = BARCODE

var d = Dictionary(
	"1NF314421199", "69944 SUNNYFIELD RD")

if (hasKey(d, address)) {
    return d[address]
} else {
    return "Unknown"
}

   

0 Kudos
43 Replies
KenBuja
MVP Esteemed Contributor

You can just add in the return to shortcut the other part of the code. You don't need to remove the rest, since it will never hit it. This is just to test whether the value getting stored in the OldMeterNumber field is what you're expecting.

0 Kudos
JD1016
by
Occasional Contributor III

Hi Ken,

Can you please provide a screenshot of where you would like me to put the code in conjunction to the rest of the lines?  I just want to make sure I am doing it correctly.

Thanks.

Jeff

0 Kudos
KenBuja
MVP Esteemed Contributor
var lookupValue = $feature.OldMeterNumber;
return lookupValue;

var d = Dictionary(
	"1NF314421199", "69944 SUNNYFIELD RD")
//rest of code
0 Kudos
JD1016
by
Occasional Contributor III

Okay.  Thank you.  I've attached a screenshot illustrating the Results section.

0 Kudos
KenBuja
MVP Esteemed Contributor

What I'm suggesting is to run this in your application, not testing it. As we said before, clicking the Test button just shows the result of the first record in your data set, not the record that was scanned in. Have you examined your data set to see what that first record looks like?

0 Kudos
JD1016
by
Occasional Contributor III

Okay.  I ran it using the ArcGIS Field Maps app and it scanned the barcode and populated the address field with the barcode number instead of the address.

0 Kudos
KenBuja
MVP Esteemed Contributor

OK, next remove line 2 from my post above so it completes the rest of the code.

0 Kudos
JD1016
by
Occasional Contributor III

Ok.  I took out "return lookupvalue;" and left everything else the same.  The barcode scans successfully and the address field is populated with "Unknown".

0 Kudos
KenBuja
MVP Esteemed Contributor

When you ran it before, it returned "1NF314421199" with no additional spaces?

0 Kudos
JD1016
by
Occasional Contributor III

There appears to be 5 extra spaces added at the end.

0 Kudos