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 III
Super User III

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

5 REPLIES 5
RandyHayes
Super User III
Super User III

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

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 III
Super User III

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@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 III
Super User III

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (71,695)