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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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