create records in a new table based on a report once a button is clicked

  • 1
  • 1
  • Question
  • Updated 2 years ago
  • Answered
I have a report in table "A" with a date filter. Upon clicking a button, I want to create in table "B" as many records as the report has.
Any suggestions?
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb

Posted 2 years ago

  • 1
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,448 Points 50k badge 2x thumb
There are different levels of automation possible.  The easiest to set up is to run your report and then use the More ...  button and select copy these records to another table.

If that is not automated enough,  then there are other methods i can describe which require more setup.
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
I am looking for more automation. Final goal would be creating the records and then sending notifications to the assigned people. I was looking at using the Mr Daniel's  image onload technique but I'm struggling with the code. 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,448 Points 50k badge 2x thumb
If the Filters on the report are standard, then the low tech way is to create a saved table to table import.     

Then create a URL formula button to run the import and refresh the report.  The button can be located on the records that you want to copy and it does not matter which button you click (ie all records will have the same button) 

The URL formula would be like

var text URL = urlroot() & "db/" & [_DBID_TABLE_B] & "?act=API_RunImport&ID=10";

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


That should run the import to create the records and refresh table A report.
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
This looks to be exactly what I need, but for some reason I can't get it to work... I created the Import and tested it. It works fine. I created the Formula URL button and placed it in the in the table I need to import from. Copied and pasted the formula from above and changed the table Id to the actual table name. Made sure that the report ID is 10, just like you predicted it... Not sure what else to look for...
Here is the formula:

var text URL = URLRoot() & "db/" & [_DBID_Field_S] & "?act=API_RunImport&ID=10";

"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,448 Points 50k badge 2x thumb
I forget about the application token.

My guess is that  if you do this to test the button without the refresh, that it will fail.

var text URL = URLRoot() & "db/" & [_DBID_Field_S] & "?act=API_RunImport&ID=10";

$URL


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


So go to your setting for the application, and Advanced Properties and disable the need for application tokens, or else you will have to create an application token and change the first line to 

var text URL = URLRoot() & "db/" & [_DBID_Field_S] & "?act=API_RunImport&ID=10"
& "&apptoken= xxxxxxxxxx";

Obviously paste in your app token code where the xxxxxx are.
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
That was it! Needles to say, you are awesome!!!
Thank you! Maybe I get to buy you a beer next week at empower?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,448 Points 50k badge 2x thumb
I will be there and if you are lucky there may be an open bar at the welcome evening so the beer you buy me could be cheap.  They will have an EMPOWER App to download on the phone for the Conference so you can look me up on it and connect.
Mark
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
Awesome! Another thing to be looking forward to :)

Thanks again!
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
I have a little follow up question. Is there a way for me to display a message window that will notify the user that  clicking the button will send an email to everyone on that report. If the user acknowledges, then send otherwise don't

Hope I'm not asking too much
 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 62,448 Points 50k badge 2x thumb
I have not tested but there was a recent post here
https://community.quickbase.com/quickbase/topics/delete-a-record-without-going-into-grid-edit-or-goi...

It contained this tip
var text URL= URLRoot() & "db/" & Dbid() & "?act=API_DeleteRecord&rid=" & [Record ID#]
& "&apptoken= xxxxxxx";

"javascript: " &
"if ( confirm('Are you sure you want to permanently delete this record ? ') == true ){ "&
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});" 
& "void(0);"&
"}"


So I assume if you just change the URL formula variable to the Run Import one, it will work.  Please post back and let me know.
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
It worked. Thank you!