How can I add a button to load the current date-time to a field

  • 3
  • 1
  • Question
  • Updated 7 months ago
  • Answered
I need to add a button to my form that will load the current timestamp into a field on my form. I think I understand how to use the Dynamic Form Rules to load the value in the finely, but I can't figure out how add the button. In searching for how to add buttons, everything seems to be several years old and does not match the current GUI. Any help would be greatly appreciated!
Photo of Jeff Mickelsen

Jeff Mickelsen

  • 294 Points 250 badge 2x thumb

Posted 8 months ago

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

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
Are you trying to make a button to be used in Virw Mode or a checkbox yo be used in Edit Mode?
Photo of Jeff Mickelsen

Jeff Mickelsen

  • 294 Points 250 badge 2x thumb
Both. Although I did not think in terms of a checkbox. I have written quite a bit of VBA code in Access and was thinking of a simple push button to execute code when depressed

Sorry if the question is dumb, but I am brand new on QuickBase and I am having some issues figuring out stuff like this.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
Here is some code which will do that.  I also have an app in the Exchange called

URL Formuals for Dummies, which helps explain how to write URL formula buttons.


vat text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord" & rid=" & [Record ID#]
& "&_fid_999=" & URLEncode(Now());

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


The first line creates a formula variable called URL which does the edit.  You will need to set 999 to the field ID which is being set to Now().  Here is some help on formula variables if you have never used them.  https://help.quickbase.com/user-assistance/formula_variables.html

The second part is a handy snippet which simply runs the URL and refreshes the page.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
Correct vat to var.
Photo of Jeff Mickelsen

Jeff Mickelsen

  • 294 Points 250 badge 2x thumb
Thanks for the quick reply.  I will definitely download your URL app from the Exchange..
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
I have a similar issue:  I have a text field "Events" which I use to log events.  Each event is just a text string:

DD/MM/YY text.

The events are listed LIFO (most recent first).

I would like to button to insert (append) the current date into the field.  From there I'll type the text.

I tried the above (correct vat to var) and nothing happens.  Here is what I have

var text URL = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" & "rid=" & [RecordID#] & "&_fid_44=" & URLEncode(Now());

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

where 44 is the field ID of the Events field.  

Please advise.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
When using this syntax, any error message are hidden.

To debug, you would comment out or remove the JavaScript refresh stuff and replace it with $URL

That will run the URL and expose any error messages.

But I will bet that your app has the need for Application Tokens enables.

So either go to sett8ngs for the app and app properties and uncheck app tokens or else create an app token and add that into the URL formula

& "&apptoken=chfhfghcggdstyujb"

To comment out a part of a formula put // at the beginning if the line.
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
Thanks.  The app tokens are already enabled (app token unchecked).

I understand how to comment out, but I don't understand what you mean by doing AND replacing it with $URL?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
One way to debug us to make a new field with just the code to do the edit and see if it works

URLRoot() & "db/" & Dbid() & "?act=API_EditRecord" & "rid=" & [RecordID#] & "&_fid_44=" & URLEncode(Now())

That will return a message to the screen as to if the edit was successful or not.
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
Nope.  From inside the record, it returned me to the home page, without creating any entry in the field.  

I should have realized this before:  I have an existing button that I use to generate an email.  (You help on that one; thanks).  After I send the email, I have been manually logging the event in the events field, as I said.

So really, what should happen is this: once I click the button to generate the email, it should do that, and then append the text to the events field.  Here is the current button

"mailto:xxxx@yyyyy.com" & 
"?subject="&[Email.SubjectLine: blahblah]&
""&"&body="&[Email.Body-blahblah]&""

I can't add the formula above, I get a compile error.  

The text to appended to the top would be:

(Now()) & "text"
(Edited)
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
I created a test field (fid=155) and tried this:

var text URLONE = URLRoot() & "db/" & Dbid() 
& "?act=API_EditRecord&_rid=" & [RecordID#] 
& "&_fid_155=" & URLEncode("Hello");

var text URLTWO = URLRoot() & "db/" & Dbid()
& "?a=dr&rid=" & ToText([RecordID#]);
$URLONE

& "&rdr=" & URLEncode($URLTWO)

that did not work.  No update to the field.

I also commented out the URLTWO etc.  and used the javascript

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

That did not work either.  

What am I doing wrong?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
This is corrected code

var text URLONE = URLRoot() & "db/" & Dbid()
& "?act=API_EditRecord&rid=" & [RecordID#]
& "&_fid_155=" & URLEncode("Hello");

The middle line in your code had an underscore.
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
Great.  Now that I got that to work. 

I figure that need to define a var which is the concat of the Today() and the current text value of hte field of interest, and then edit the record to set to field to that value.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,570 Points 50k badge 2x thumb
Right, like

var EventAndType = ToText(Today()) & " some other Text”;

Or maybe

var EventAndType = ToText(Today()) & " “ & [Event Type Field];
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
I'm using the latter form.  
Last question:  I need a carriage return after ToText(Today()).  What is the coding for that?
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
I figured it out.  Thanks.
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
actually, I didn't. I thought I could use "%0D%0A" but that does not work.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 52,656 Points 50k badge 2x thumb
The Carriage Return character is backslash n

So

"\n"

This will go to edit mode,

var text URLTWO = URLRoot() & "db/" & Dbid()
& "?a=er&rid=" & ToText([RecordID#]);
Photo of ROBERT SACHS

ROBERT SACHS

  • 440 Points 250 badge 2x thumb
Ah: and I need to put the record into edit mode.