web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Help with Scan to Coll...
Power Apps
Unanswered

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)
)
)

Categories:
I have the same question (0)
  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    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.

     

  • Apolmans1 Profile Picture
    28 on at
    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.

  • Apolmans1 Profile Picture
    28 on at

    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!

  • Verified answer
    StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    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)
    );

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard