cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JimSutt
Helper III
Helper III

Remove Matching SQL Server Record When Looping Through Collection

I need help with the syntax of the Remove() function when attempting to delete records from SQL Server that are referenced in a collection.  In the following logic, the LookUp() function returns the first record in the database, regardless of the record I am trying to delete.  Note that ITEM_SCAN and DATETIME are columns in both the collection and the SQL Server table.

 

 

ForAll(
   collectItem,
   If(
      DELETED=true,
      Remove(
         ITEM_TABLE,
         LookUp(ITEM_TABLE,And(ITEM_SCAN=ITEM_SCAN, DATETIME=DATETIME))
      )
   )
)

 

 

I tried to modify the LookUp() syntax with the following, but it returns nothing:

 

LookUp(ITEM_TABLE,And(ITEM_SCAN=collectItem[@ITEM_SCAN], DATETIME=collectItem[@DATETIME]))

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@JimSutt 

Please consider changing your Formula to the following:

ForAll(
   Filter(collectItem, DELETED) As _item,
   RemoveIf(ITEM_TABLE,
       ITEM_SCAN = _item.ITEM_SCAN && DATETIME = _item.DATETIME
   )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@JimSutt 

Please consider changing your Formula to the following:

ForAll(
   Filter(collectItem, DELETED) As _item,
   RemoveIf(ITEM_TABLE,
       ITEM_SCAN = _item.ITEM_SCAN && DATETIME = _item.DATETIME
   )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Hi @RandyHayes , when I apply your changes, I get a warning on the "ITEM_SCAN = _item.ITEM_SCAN" stating: 

 

Incompatible type.  We can't evaluate your formula because the values being compared in the formula aren't the same type

 

RandyHayes
Super User
Super User

@JimSutt 

Well, there's an issue to resolve!   What type of column is ITEM_SCAN, and how are you storing it in your collection?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes , good call.  I am using the Barcode Scanner control to load the values into the collection in the ITEM_SCAN column.  By surrounding the value of the scan with the Value() function, I'm able to get the type to match the column in the database, which is set as an integer.

Set(varItem,Value(BarcodeScannerMulti.Value));

  Getting the value of a value seems counter-intuitive, but that was the necessary step.  Now your code works like a charm.  Thank you for all the assistance!

RandyHayes
Super User
Super User

@JimSutt 

Very good!  Yes in the case of the .Value it represents what the scanner scanned.  In this case it is a text property.  So converting to integer is the key.

Pleasure to help.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,595)