How do you format a API_PurgeRecords button?

  • 0
  • 1
  • Question
  • Updated 6 months ago
  • Answered
I'm sorry but I'm not very experienced in coding. I'm trying to just create a button on a table or home page that will allow me to use the API_PurgeRecords to delete some records on a table based off a checkbox field. How would I format a URL formula field or text page to create a button that will do this?
Photo of Brandon

Brandon

  • 120 Points 100 badge 2x thumb

Posted 6 months ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,438 Points 20k badge 2x thumb
Typically the API_Purge is used to delete a record and all its children and all its grandchildren.  In order to define which tables/relationship records to purge you have to define that within a code page.  I've never used the purge without a code page to define the variables.  

Its not something I'd want to put in a button.

No if you are trying to make a single delete button to clear a single record... that is an appropriate button code.

"javascript:DoDelete(\"Record\", gReqDBID,"&[Record ID#]&")"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,486 Points 50k badge 2x thumb
There is a low tech solution


The API_PurgeRecords API as descibed here https://help.quickbase.com/api-guide/index.html#purgerecords.html can have a parameter to filter which records get purged.

URL Alternative

https://<em>target_domain</em>/db/<em>target_dbid</em>?a=API_PurgeRecords&qid=10<br>&ticket=<em>auth_ticket</em>&apptoken=<em>app_token</em><br>

where target_domain is the domain against which you are invoking this call, for example, intuit.quickbase.com.


So you can make a report where the filter is that checkbox being true and hide the report form all role so no one is likely to mess with it.  i would also put in the description of the report to not delete or alter the report.

so the URL formula would look like this below.  The javascript code will simply run the  formula variable called URL to do the purge and refresh the page.


var text URL = urlroot() & "db/" & [_DBID_TABLE name goes here] & "?act=API_PurgeRecord&qid=99";

"javascript:" &

"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"


You can put that into a URL formula field.  If you want to have a dashboard button, make the URL formula on a field somewhere in the app and expose the code by by suppressing the link text.  Then copy and paste the code into a URL dashboard button element.

I would test this first on a Copy of your app, as when you purge records they are "gone baby gone".

There is also another way to alter the URL to not depend on a report qid, but rather just use query parameters.  That would actually be a bit safer as that way you would not have a risk of someone removing the filers on your report and then the purge might purge everything.


Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,486 Points 50k badge 2x thumb
My solution is very low tech.  Just make a report and filter it like any report is filtered.  Then save the report and observe the qid# in the URL when you run it.

Or are you in fact asking how to use query parameters to filter the report which involves more syntax.  My method is no code at all, just make a report with the correct filters,  and then use that report qid in the API call.
Photo of Brandon

Brandon

  • 120 Points 100 badge 2x thumb
Actually I think I was looking at it the wrong way and the solution you suggested should give me everything I need. 
Thank you!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,486 Points 50k badge 2x thumb
:) I'm all about Stupid Simple and just move on to the next obstacle.
Photo of Brandon

Brandon

  • 120 Points 100 badge 2x thumb
I'm sorry but I must be doing something wrong because I tried copying your code and it doesn't seem to be doing anything. I tried putting the following code into a URL formula field:
var text URL = URLRoot() & "db/" & [_DBID_JOBS] & "?act=API_PurgeRecord&qid=93";
"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"

When I press the button it doesn't do anything, nothing happens. I'm supposed to be putting this code into a URL formula field on the table that the report exists on correct?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,486 Points 50k badge 2x thumb
Yes, it is put into a URL formula field.

To debug the formula, first make just a formula like this
That way the error message will be exposed.


URLRoot() & "db/" & [_DBID_JOBS] & "?act=API_PurgeRecord&qid=93"

The first problem is that the API is actually 
API_PurgeRecords  with an "s" on the end.

The typical second possible problem is that either you would need to disable the need for application tokens in the Advanced settings for the app or else include a line like this

& " &apptoken= xxxxx (insert app token here)" 
Photo of Jim Harrison

Jim Harrison

  • 1,770 Points 1k badge 2x thumb
Automations (in beta) will also do this. I think you can do it with Actions too but have never tried. 
The Action triggers when the check box is checked, which is done using the button.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,486 Points 50k badge 2x thumb
I don't think that an Action can delete, it can only add or edit.

Yes, An Automation can delete, but when I tried  to use one for a real client, the deletions were painfully slow to run, so I abandoned that step in the Automation and did the delete with the API Purge as that was instant.  We will see if delete is any different when it goes into GA (general Availability) release.

In my case I was deleting hundreds or thousands of records and the automation was just too slow. I think it deleted them one by one on some slow paced basis as opposed to more of a mass delete.  
Photo of Jim Harrison

Jim Harrison

  • 1,770 Points 1k badge 2x thumb
Good to know. So far we have only deleted a few child records at a time. It works well and is easy to set up.