How do I genaddrecord and save it without any redirect on a click? I want this to happen in the back end.

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • In Progress
Photo of Sania

Sania

  • 476 Points 250 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,978 Points 1k badge 2x thumb
first you'll need the image onload technique so you can load javascript pages on your forms/reports. After that's installed open up the page, add this code to edit or add views wherever you want it to run.

Then create a formula text button that you'll use to trigger it
Name the id of the button qbu_something instead of qbu_yourCustomBtn

dbidVariable should be the table ID like this
var dbidTableName = "aj867234jaf";

The example below create a record and assigns the related record value to the parent record id (kRid) you can type that in your console while on a record page and it will tell you the record id.
_fid_1 is your field ID that you're updated so in my case the related record field in the child table is _fid_10 and 9 is a text field and I enter purchase approved. 

then place this code after you've updated the values in that javascript page you made under the proper view (add/edit/report)

$('#qbu_yourCustomBtn').on('click',
            function() {
                $.post(dbidVariable, {
                    act: "API_AddRecord",
                    _fid_10: kRid,
                    _fid_9: "Purchase Approved"
                }, function(resp) {
                    console.dirxml(resp)
                   //Do something with the response.
                })
            });

Let me know if this makes sense or if you need direct help setting this up.
chuck@chuck.support
Good luck!
Photo of Chuck Grigsby

Chuck Grigsby

  • 1,978 Points 1k badge 2x thumb
also in place of the //Do something,
you could put alert("New record added") which would show a dialog box if you still wanted the user to know it went through.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,326 Points 50k badge 2x thumb
Sania,

Can you describe what you want to happen when the user clicks.  I'm 99% sure that this can be done natively without resorting to the image onload technique.
Photo of Sania

Sania

  • 476 Points 250 badge 2x thumb
I want to click on a button, that will create a record and save it with some pre populated fields. Basically, I don't want user to edit the add form but just save it with the information that is pre populated 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,326 Points 50k badge 2x thumb
so this can be done natively.

When the user clicks the button do you just want to show a quiet pop up saying like "Record Added", or do you want top refresh the record the user is on to perhaps show that a child record was added.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,326 Points 50k badge 2x thumb
This is an example:

var text URL= URLRoot() & "db/" & [_DBID_TABLE_1] & "?act=API_AddRecord"
& "&_fid_6=" & URLEncode ([Record ID#])
& "&_fid_7=" & URLEncode ([Status])
& "&_fid_10=" & URLEncode ([Name])

& "&apptoken=" & "XXXX";


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

Get the API Add Record working first.  Then add in the javascript refresh part.  The reason is that you need to see if there are any error messages and that refresh will hide the success or failure message.