Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Help with Scan to Collection

(0) ShareShare
ReportReport
Posted on by 28

Hey there, I am trying to get my on scan property to add to the quantity of the scanned item if it's scanned multiple times, rather than adding more entries. I have no idea what I am doing wrong as the below seems to make sense but every scanned item goes in as a new record entry, help! - what am I missing here? - Here is what I've got:

 

Set(
CurrentRecord,
LookUp(
'Copy of catalogue - 07-20-2021',
Value(BarcodeScanner1.Value) = GTIN,
ThisRecord
)
);
Set(
Barcode1,
Value(BarcodeScanner1.Value)
);
Set(
Varscn,
true
);
Collect(
colLimit,
{
Limit: CurrentRecord.'Dried Flower Cannabis Equivalency',
Title: CurrentRecord.Title
}
);
If(
Sum(
colLimit.Limit,
Limit
) > 30,
Set(
varWarning,
true
)
);
If(
Sum(
colLimit.Limit,
Limit
) <= 30,
If(
CurrentRecord.GTIN = Barcode1,
Patch(
colShoppingCart1,
LookUp(
colShoppingCart1,
Barcode1 = Barcode,
ThisRecord
),
{
Qty: Qty + 1,
Title: CurrentRecord.Title
}
),
Collect(
colShoppingCart1,
{
Title: CurrentRecord.Title,
MemberID: VarMember,
ProductPrice: CurrentRecord.'Unit Price',
SKU: CurrentRecord.'OCS Variant Number',
Size: CurrentRecord.Size,
Barcode: CurrentRecord.GTIN,
Qty: Value(1),
Equiv: CurrentRecord.'Dried Flower Cannabis Equivalency',
Image: CurrentRecord.'Image URL',
Subtotal: CurrentRecord.'Unit Price',
Remain: CurrentRecord.'Eaches Per Master Case' - 1,
RemStock: CurrentRecord.'Eaches Per Master Case' - 1
}
)
);
Patch(
'Copy of catalogue - 07-20-2021',
CurrentRecord,
{'Eaches Per Master Case': CurrentRecord.'Eaches Per Master Case' - 1}
),
Remove(
colLimit,
Last(colLimit)
)
)

  • Verified answer
    Re: Help with Scan to Collection

    Hi @Apolmans1

     

    Here is the updated code.

     

    Set(
     Barcode1,
     Value(BarcodeScanner1.Value)
    );
    Set(
     CurrentRecord,
     LookUp(
     'Copy of catalogue - 07-20-2021',
     Barcode1 = GTIN,
     ThisRecord
     )
    );
    Collect(
     colLimit,
     {
     Limit: CurrentRecord.'Dried Flower Cannabis Equivalency',
     Title: CurrentRecord.Title
     }
    );
    If(
     Sum(
     colLimit.Limit,
     Limit
     ) > 30,
     Set(
     varWarning,
     true
     );
     Remove(
     colLimit,
     Last(colLimit)
     ),
     If(
     CurrentRecord.GTIN = Barcode1,
     Patch(
     colShoppingCart1,
     LookUp(
     colShoppingCart1,
     Barcode1 = Barcode,
     ThisRecord
     ),
     {
     Qty: Qty + 1,
     Title: CurrentRecord.Title
     }
     );
     Patch(
     'Copy of catalogue - 07-20-2021',
     CurrentRecord,
     {'Eaches Per Master Case': CurrentRecord.'Eaches Per Master Case' - 1}
     ),
     Collect(
     colShoppingCart1,
     {
     Title: CurrentRecord.Title,
     MemberID: VarMember,
     ProductPrice: CurrentRecord.'Unit Price',
     SKU: CurrentRecord.'OCS Variant Number',
     Size: CurrentRecord.Size,
     Barcode: CurrentRecord.GTIN,
     Qty: 1,
     Equiv: CurrentRecord.'Dried Flower Cannabis Equivalency',
     Image: CurrentRecord.'Image URL',
     Subtotal: CurrentRecord.'Unit Price',
     Remain: CurrentRecord.'Eaches Per Master Case' - 1,
     RemStock: CurrentRecord.'Eaches Per Master Case' - 1
     }
     )
     )
    )

     

     For testing

    • Place one text input control
    • Place one button on set exact same code as "OnScan"
    • Change the below code to take scanning from text control instead of scanner
    Set(
     Barcode1,
     Value(TextInput1.Text)
    );
  • Apolmans1 Profile Picture
    Apolmans1 28 on at
    Re: Help with Scan to Collection

    Ok now I am just lost, last night this same code at least was adding the scanned items to my collection as new items every time, as of this morning when I tried it wont scan at all.... I probably messed with something before bed but I don't know what the heck I did to break it... The one thing I noticed about the above code was that I was comparing the wrong fields on the second if statement, changed that to compare my scanned value to a look up of the collection and since then it won't scan at all, even if I revert back... WTF!

  • Apolmans1 Profile Picture
    Apolmans1 28 on at
    Re: Help with Scan to Collection
    Set(
     CurrentRecord,
     LookUp(
     'Copy of catalogue - 07-20-2021',
     Value(BarcodeScanner1.Value) = GTIN,
     ThisRecord
     )
    );
    Set(
     Barcode1,
     Value(BarcodeScanner1.Value)
    );
    Set(
     Varscn,
     true
    );
    Collect(
     colLimit,
     {
     Limit: CurrentRecord.'Dried Flower Cannabis Equivalency',
     Title: CurrentRecord.Title
     }
    );
    If(
     Sum(
     colLimit.Limit,
     Limit
     ) > 30,
     Set(
     varWarning,
     true
     )
    );
    If(
     Sum(
     colLimit.Limit,
     Limit
     ) <= 30,
     If(
     CurrentRecord.GTIN = Barcode1,
     Patch(
     colShoppingCart1,
     LookUp(
     colShoppingCart1,
     Barcode1 = Barcode,
     ThisRecord
     ),
     {
     Qty: Qty + 1,
     Title: CurrentRecord.Title
     }
     ),
     Collect(
     colShoppingCart1,
     {
     Title: CurrentRecord.Title,
     MemberID: VarMember,
     ProductPrice: CurrentRecord.'Unit Price',
     SKU: CurrentRecord.'OCS Variant Number',
     Size: CurrentRecord.Size,
     Barcode: CurrentRecord.GTIN,
     Qty: Value(1),
     Equiv: CurrentRecord.'Dried Flower Cannabis Equivalency',
     Image: CurrentRecord.'Image URL',
     Subtotal: CurrentRecord.'Unit Price',
     Remain: CurrentRecord.'Eaches Per Master Case' - 1,
     RemStock: CurrentRecord.'Eaches Per Master Case' - 1
     }
     )
     );
     Patch(
     'Copy of catalogue - 07-20-2021',
     CurrentRecord,
     {'Eaches Per Master Case': CurrentRecord.'Eaches Per Master Case' - 1}
     ),
     Remove(
     colLimit,
     Last(colLimit)
     )
    )

    Here is the code formatted correctly, please let me know what I'm doing wrong, code works to add new items to the cart/collection but will add a second entry rather than patching the exiting one on the second scan.

  • Re: Help with Scan to Collection

    Hi @Apolmans1

     

    We can use Patch(data source, Collection1) when a collection has the right keys. Can you format your code and share it with us. That will be easy to read and understand.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,495

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,822

Leaderboard