Arcade Expression for Barcode Scanning

3453
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
JD1016
by
Occasional Contributor III

I modified the code as such...again...newby.  Unfortunately, it gives me the same result as before...the entire barcode with the correct address.  It seems to be ignoring the Mid statement I've added in addition to the other code modifications.  Can you please take a look?

var lookupValue = Trim($feature.OldMeterNumber);
var meter = Mid(lookupValue, 3, 9);

var d = Dictionary(
	"314421199", "69944 SUNNYFIELD RD");

if (hasKey(d, meter)) {
    console("      >>> " + meter + " was found! " + "Address: " + d[meter]);
    return d[meter];
} else {
    console("      >>> The meter was NOT found!");
    return "Unknown";
};

  Thank you! 

0 Kudos
KenBuja
MVP Esteemed Contributor

This code works as expected in the Arcade Playground. As a note, you don't need the 9 in the Mid function (var meter = Mid(lookupValue, 3);), since it apparently defaults to the length of the string.

 

0 Kudos
JD1016
by
Occasional Contributor III

This is definitely a bit confusing.  The barcode continues to supply the entire code including the leading three characters of "1NF".  The only change I applied was the note you indicated regarding the "9".   If there is an issue, I'm just not seeing it.

0 Kudos
JD1016
by
Occasional Contributor III

Hi Ken,

I'm going to post this question as its own entity.  In adding on to my original question, that was graciously solved by yourself, I feel it creates a disadvantage for someone attempting to gain insight into the discussion coupled with the fact its contained within an already completed topic.  By all means, please respond though if you have any additional comments about my conundrum.

Thank you.

Jeff

0 Kudos