Barcode Parsing and Java Trim() Function

343
1
07-07-2022 08:22 AM
ZacharyJaffe
New Contributor III

Hi All,

I am working on building a Survey123 form where I am populating 14 fields from a single bar code scan. I know which string numbers correlates to which field, for example the ‘model’ field is characters 0-19 and can parse the data accordingly. In reality, the ‘model’ value will always be between 8 -12 characters long, never filling the 20 character spaces allotted for it within the bar code, therefore leaving white space at the end of the data entry. I would like to remove the whitespace after the entry and am trying to use the trim() Java script function. I have practically zero Java experience but have watched a handful of the Survey123 and Java YouTube videos. This is what my script looks like below and it does work when testing it:

ZacharyJaffe_0-1657206742490.png

When I copy the java script into my excel form and try to save it, it looks like this:

ZacharyJaffe_1-1657206742493.png

I am trying to parse the data and trim the blank space in the same calculation cell and get the following error:

“There has been a problem trying to replace ${<model>} with the XPath to the survey element named ‘<model>’. There is no survey element with this name.”

I try to create a calculate row with the Java script in it as pictured below and get the same error message.

ZacharyJaffe_2-1657206742495.png

I am pretty stuck here trying to figure out how to trim/get rid of the white space and any help would be greatly appreciated!

Thank you very much,

Zach

0 Kudos
1 Reply
ZacharyJaffe
New Contributor III

Anyone have any ideas? Any advice would be appreciated.

Thanks!

 

0 Kudos