Discussions

Expand all | Collapse all

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

QuickBaseCoach Dev./Training05-18-2018 21:47

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

    Posted 04-22-2018 03:25
    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!


  • 2.  RE: How can I add a button to load the current date-time to a field

    Posted 04-22-2018 15:06
    Are you trying to make a button to be used in Virw Mode or a checkbox yo be used in Edit Mode?


  • 3.  RE: How can I add a button to load the current date-time to a field

    Posted 04-22-2018 16:35
    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.


  • 4.  RE: How can I add a button to load the current date-time to a field

    Posted 04-22-2018 20:24
    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.


  • 5.  RE: How can I add a button to load the current date-time to a field

    Posted 05-18-2018 21:47
    Correct vat to var.


  • 6.  RE: How can I add a button to load the current date-time to a field

    Posted 04-23-2018 22:56
    Thanks for the quick reply.  I will definitely download your URL app from the Exchange..


  • 7.  RE: How can I add a button to load the current date-time to a field

    Posted 05-18-2018 21:39
    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.


  • 8.  RE: How can I add a button to load the current date-time to a field

    Posted 05-18-2018 21:53
    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.


  • 9.  RE: How can I add a button to load the current date-time to a field

    Posted 05-18-2018 22:15
    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?


  • 10.  RE: How can I add a button to load the current date-time to a field

    Posted 05-18-2018 22:23
    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.


  • 11.  RE: How can I add a button to load the current date-time to a field

    Posted 05-18-2018 22:43
    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


  • 12.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:06
    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?


  • 13.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:15
    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.


  • 14.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:18
    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.


  • 15.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:25
    Right, like

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

    Or maybe

    var EventAndType = ToText(Today()) & " � & [Event Type Field];


  • 16.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:30
    I'm using the latter form.  
    Last question:  I need a carriage return after ToText(Today()).  What is the coding for that?


  • 17.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:38
    I figured it out.  Thanks.


  • 18.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:41
    actually, I didn't. I thought I could use "%0D%0A" but that does not work.


  • 19.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 11:56
    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#]);


  • 20.  RE: How can I add a button to load the current date-time to a field

    Posted 05-19-2018 03:32
    Ah: and I need to put the record into edit mode.