Button to check a field and save the record (Submit button)

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
I want to put a "submit" button on my form that allows for:
1. A checkbox field to be checked [Invoice Submitted]
2. The record to be saved
3. It must work whether or not it's a new record or one that has been saved before.
4. I was using a formula-text  but formula-URL is fine that that's what I should be doing.

I was trying to get it to update the field and save the record, but the code doesn't work, I believe because it has to be saved first

var text Update=URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#]) & "&_fid_20=1"& "&apptoken= *********";
"<a id='saveButton' class='Vibrant Success' onclick='DoSaveAdd()' href='#'>Submit Invoice</a>"
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
I guess an if(IsNull([Record ID#]),
would allow me to have two strings one for API_EditRecord and one for API_AddRecord but I don't understand how to get the AddRecord to work and then how to imbed the two options into the IF statement with correct Syntax. 


I would think Javascript would make sense but I know little about Javascript. 
 
Seems like Javascript would just check the box and hit the "save" button regardless of whether it was add to edit?



,
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
My suggestion is to just have the user save the record and then give them a button to "Submit", when in View mode.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
That's feeling like the right answer at this point as this gets more and more complicated :(
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
I thought this code worked but now it won't. It saves but doesn't check the fid_20 to a true:

var text Update=URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & ToText([Record ID#]) & "&_fid_20=1"& "&apptoken= xxx";
"<a id='saveButton' class='Vibrant Success' onclick='DoSaveAdd()' href='#'>Submit Invoice</a>"
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
You are just guessing at code.  Well, I suppose that we all do that sometimes.  

I don't know if there is a way to do what you ask without javascript, but that code certainly that won't work.

You are defining the formula variable called "Update".  But then the actual code does not even refer to that formula variable.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
You got me, but I'm leaning on the fly. It's not like I can quit my job and go to school for this stuff. Running a business and all...
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Ah. I switched it from Formula-Text with HTML Checked to Formula URL and that works in view mode. I am then hiding the submit button in edit/add mode.

var text URLONE = URLRoot() & "db/" & Dbid()& "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_20=1"& "&apptoken= xxxxx";

var text URLTWO = URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#];
  
$URLONE
& "&rdr=" & URLEncode($URLTWO)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
If you just want to edit the record to check a checkbox, yes that is easy.  
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
Do you also have a need to check that checkbox from a report but no want to have different buttons?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
this syntax works well as long as there are no redirects in your URL

var text URL = = URLRoot() & "db/" & Dbid()& "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_20=1" & "&apptoken= xxxxx";


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


The magic is that after it does the edit it will refresh the"page" whether that is a record or a report.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
Edit: (just one = is enough!)

 var text URL =  URLRoot() & "db/" & Dbid()& "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_20=1" & "&apptoken= xxxxx";
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
This is the only school there is for the type of questions you are asking.  There are a bunch of tricks to learn.  Once you learn them, you just keep re-using them.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
Well you'd think I could at least have realized that I declared a variable and then never called it. :(
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
It wouldn't hurt to have it work from a report, allowing a user to submit from there after editing say multiple invoices. Do I use a formula text or URL type?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
formula URL
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
I did add to my report as well, and presto, like magic.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
Be sure to give the button a pretty color.
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
This is excellent. Thanks. I had to remove what appeared to be a stray "=" in the first assignment so it now looks like this. And yes, a green button was mandatory for this one :)

var text URL = URLRoot() & "db/" & Dbid()& "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_20=1" & "&apptoken= xxxxx";


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

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
It even works if it was a button on an embedded report  of records on a record.  ie on a child table on a report on a record.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,006 Points 50k badge 2x thumb
btw, what is your "day job" in real life?  What kind of business are you running?
Photo of Stephen

Stephen

  • 760 Points 500 badge 2x thumb
own/run a niche toy company: www.weebelievers.com