Forum Discussion

Grant's avatar
Grant
Qrew Member
2 years ago

Pipeline - Delete Record

Hi,

I have a Couple of Tables, say Table A , Table B and Table C.
Table C is a Helper table with records of sequential numbers I am using as a loop counter.
e.g. QTY is 5 so 5 related Part Records with a Blank serial number field are created in Table B. 

Table A Has a Numeric Quantity field (QTY) and a Part Number field
I already have a Pipeline work so when you save a record in Table A it creates in Table B QTY x  Records with a Part Number field and say say a Serial Number Blank serial number field
Adding records or modifying upwards is working.

What I'm struggling with is a Delete if the Table A QTY number is changed downwards.


If I go back and edit that record and change QTY to 3, I want to delete two of the related records in Table B (preferably the latest created).

I have a field "Difference" in Table A that records the change in QTY so I know how many times to Add/Delete on a QTY modification

I currently have a 
A. Search Records on Table C
For Each
 Do 
 B. Search Records on Table B for Record ID matching the appropriate Table A Record ID
 C. Delete Record

Step C -Delete Record doesnt work because the Search Record in Step B returns an array of multiple matching records.

Am I on the right path - how would I delete the latest record from search in Step B?

Thanks.







------------------------------
Grant
------------------------------

2 Replies

  • Grant's avatar
    Grant
    Qrew Member

    I've still been working on this issue, and trying a different approach.
     have created a Quickbase API - Make request that can retrieve the data I need. 

    https://api.quickbase.com/v1/reports/1/run?tableId=xxxxx&top={{a.abs_difference}}

    Is it possible to do a second Make Request to PurgeRecords from the result of the previous query? I can't figure out the correct syntax.
    http://yyyy.quickbase.com/db/xxxx?a=API_PurgeRecords&query={8.EX.????}



    ------------------------------
    Grant
    ------------------------------
    • DougHenning1's avatar
      DougHenning1
      Community Manager

      Instead of searching all records, what about a trigger on the quantity field in Table A.  Then you can use $prev to get the previous value and only continue if it decreased.

      A) Trigger on Record Update, quantity field change on Table A
      B) If a.quantity > a.$prev.quantity
          Stop
      C) Search Table B matching appropriate Table A record, limit= {{ a.$prev.quantity - a.quantity }}
      For Each C
         D) Delete record

      I think you were on the right track at the beginning, but you didn't have a loop around the Delete record step.

      Hope that helps!



      ------------------------------
      Doug Henning
      ------------------------------