cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sajarac
Super User
Super User

Scanning a QR Code and saving to SPL

Hello community.

 

Looking for some help here:

 

I am currently creating an app to scan QR codes. The QR code generated data is from a HTML Label, and basically is a string with the values of the selected record plus & Char(10) in between each field.

 

ie = BrowseGallery1.Selected.Title & Char(10) "&  BrowseGallery1.Selected.ID & char(10) ............etc.

 

I am getting the QR code with no issues. Now what I need to know is once the QR code is scanned I need to split that value or string to save each value in a Share point. Something like to break that line of text, create a collection and save each scanned code into a new row in my Share point list.

 

Somebody could please point me in the right direction?

 

Many thanks 

1 ACCEPTED SOLUTION

Accepted Solutions

@sajarac 

 

Sorry I missed the other fields, here the updated formulas:

Label1 = First(Split(ThisItem.Barcodeinfo, Char(10))).Result
Label2 = Last(FirstN(Split(ThisItem.Barcodeinfo, Char(10)), 3)).Result
Label3 = Last(FirstN(Split(ThisItem.Barcodeinfo, Char(10)), 4)).Result
Label4 = Last(FirstN(Split(ThisItem.Barcodeinfo, Char(10)), 2)).Result

(I might mixed up the labels)

 

Basically, Split(ThisItem.Barcodeinfo, Char(10)) will split each part of your barcode into an array (based on the Char(10) as delimiter).

Then, we have to get the right item at the right place. As PowerApps didn't provide a way to get an item by index, we need to use this workaround with Last and FirstN formulas. By example, for the 3d element:

  1. FirstN allows to get a subarray with the 3 first items.
  2. Last allows to get the last item of this subarray (ie. the 3d element of the main array)

 

Hope it will help

View solution in original post

11 REPLIES 11
lcimon
Resolver I
Resolver I

Hello,

 

You can use the split function to break that line of text as following:

Split(YourVariable, Char(10))

 

With your example, you will get an array like ["TitleValue", "IDValue"].

 

Then use the Patch function to save each row in your SharePoint list with something like:

//Solution 1: If you don't need to add extra values
Patch(YourSharePointList,
    RenameColumns(Split(pQRCodes, Char(10)), "Result", "YourColumnName")
)

//Solution 2: If you need to add extra values
ForAll(Split(pQRCodes, Char(10)),
    Patch(Gateways,Defaults(Gateways), {YourColumnName: ThisRecord.Result, OtherColumn: XXX})
)

 

Hey, Thank you very much for the prompt response.

 

However I have a small issue.

 

For my OnScan property I have the following:

 

Collect(collectMultiScan, {Barcodeinfo: BarcodeScanner.Value})

 

In my gallery I was able to get the first line but with some issue doing this:

 

Left(ThisItem.Barcodeinfo, Find(" ", ThisItem.Barcodeinfo)-1)

 

But I guess still wrong.

 

And after apply your formula I am getting error: expected a text value

 

lcimon
Resolver I
Resolver I

@sajarac,

 

I'm in trouble to understand what you want to achieve. Could you please elaborate a bit, please ? 

Ok, Sorry for the mess.

 

First thing first:

The parameters for my QR Code are like this:

 

HtmlText = 

varRecord.MID& Char(10)&"ID: " &varRecord.Title & Char(10)&DataCardValue2&" Lbs" & Char(10) &"CreatedBy: " &varRecord.Employee

 

 

This value is placed at the end of my Image property like this:

 

"https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl="&QRdata

 

That is how is generated the QR Code.

 

Now to read the QR Code I have my app 

Button Scan

On Scan = Collect(collectMultiScan, {Barcodeinfo: BarcodeScanner.Value})

 

I have a Gallery =

Item = CollectMultiscan

 

In my Gallery I have 2 labels so far trying to split the QR Code Code

 

Label1 = Left(ThisItem.Barcodeinfo, Find(" ", ThisItem.Barcodeinfo)-1)

Label2 = Right(ThisItem.Barcodeinfo, Find("CreatedBy:", ThisItem.Barcodeinfo)+2)

 

And I have a button to patch my gallery

 

Submit = 

ForAll(collectMultiScan, Patch(TallySheet, Defaults(TallySheet),{Title:Label1.Text, Operator:Label2.Text}));Clear(collectMultiScan)

 

 

This is what I have. I just need to patch my SPL "TallySheet" with all the values in my gallery matching Title = Title, Operator = Operator.

 

Make sense?

 

Sorry again

 

sajarac
Super User
Super User

the issue could be maybe because here I am using Char(10) instead of <br>?

 

HtmlText = 

varRecord.MID& Char(10)&"ID: " &varRecord.Title & Char(10)&DataCardValue2&" Lbs" & Char(10) &"CreatedBy: " &varRecord.Employee

lcimon
Resolver I
Resolver I

@sajarac,

 

Thanks for the clarification.

 

So If I well understand, once a barcode is scanned, it is added into a Gallery where you want to split its content in 2 separate labels.

A simple solution could be the following:

Label1 = First(Split(ThisItem.Barcodeinfo, Char(10))).Result
Label2 = Last(FirstN(Split(ThisItem.Barcode, Char(10)), 2)).Result

Your patch formula seems to be correct and compatible with these formulas.

sajarac
Super User
Super User

Hey @lcimon ,thanks again for your help. Yes I need to split that Barcode string but where I am getting mental is because I need to split into 4 different pieces.

Label1 = MID

Label2 = Title

Label3 = DataCardValue2

Label4 = Employee

 

I was able to get the Label1 and Label 4. But nothing for the values in the middle.

 

 

 

@sajarac 

 

Sorry I missed the other fields, here the updated formulas:

Label1 = First(Split(ThisItem.Barcodeinfo, Char(10))).Result
Label2 = Last(FirstN(Split(ThisItem.Barcodeinfo, Char(10)), 3)).Result
Label3 = Last(FirstN(Split(ThisItem.Barcodeinfo, Char(10)), 4)).Result
Label4 = Last(FirstN(Split(ThisItem.Barcodeinfo, Char(10)), 2)).Result

(I might mixed up the labels)

 

Basically, Split(ThisItem.Barcodeinfo, Char(10)) will split each part of your barcode into an array (based on the Char(10) as delimiter).

Then, we have to get the right item at the right place. As PowerApps didn't provide a way to get an item by index, we need to use this workaround with Last and FirstN formulas. By example, for the 3d element:

  1. FirstN allows to get a subarray with the 3 first items.
  2. Last allows to get the last item of this subarray (ie. the 3d element of the main array)

 

Hope it will help

sajarac
Super User
Super User

Yeaaahhhh. Finally the light at the end.

I got the 4 fields divided which is great. Just one minor thing and I guess I have to figure out. Because in my QR Code it shows for instance:

ID: 00000-27

25 EA

Operator: JK

 

I need to remove using the substitute function to only get:

00000-27

25

JK

 

Other than that your solution is great!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,838)