Discussions

Expand all | Collapse all

On Click Counter

  • 1.  On Click Counter

    Posted 06-09-2017 16:07
    I'm looking for a way to crate a counter that will increment the value in a field by 1 each time I push a button. I was trying to do it by using API_EditRecord&rid but It's eluding me.


  • 2.  RE: On Click Counter

    Top
    Contributor
    Posted 06-09-2017 16:36

    There are two issues you have to deal with.

    First, what page are you on and what is being displayed? You can press a button to increment the counter using script and the API but if the field value is being displayed on the current page you have to somehow deal with the issue of displaying the new value of the counter so as to not confuse your users.

    Second, you first need to get the current value of the counter from the page you are on or through the API then increment and save the counter using API_EditRecord.

    The script is simple but you have to define the workflow you want.



  • 3.  RE: On Click Counter

    Posted 06-09-2017 16:51
    Try this

    var number NewValue = [My counter field] +1;

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
    & "&_fid_99=" & ToText($NewValue);


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

    // replace the 99 with the field ID of the counter field.
     


  • 4.  RE: On Click Counter

    Posted 06-09-2017 16:51
    Dan,
    I would be on the same page the increment will occur. Displaying the new number on the page is not that important because users will not need to see this field. The field will be used as a trigger for creation of a child record as well as being part of a text field on the child record we just created. A type of versioning, if you would.


  • 5.  RE: On Click Counter

    Posted 06-09-2017 16:54
    If you want a message to the user with bout a screen refresh you can do this
    var number NewValue = [My counter field] +1;

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
    & "&_fid_99=" & ToText($NewValue);



    "javascript:" &
    "$.get('" & 
    $url & 
    "',function(){" &
    "$.jGrowl('Children have been added', {life: 5000, theme: 'jGrowl-green'});" &
    "});" &
    "void(0);


  • 6.  RE: On Click Counter

    Posted 06-09-2017 16:57
    Trying this now.
    Thanks Mark!


  • 7.  RE: On Click Counter

    Posted 06-09-2017 17:17
    It worked. I just needed to add the apptoken to it.
    Thanks Mark!


  • 8.  RE: On Click Counter

    Posted 08-03-2018 18:11
    Absolutely off topic, but are there other colors for jGrowl? Haven't managed any other than the "theme: 'jGrowl-green'


  • 9.  RE: On Click Counter

    Top
    Contributor
    Posted 06-09-2017 17:30

    This is the essential part of the code to increment a [counter] field with fid=6:

    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=584



  • 10.  RE: On Click Counter

    Posted 06-09-2017 18:17
    Awesome! I got the best of the two worlds. The flat one and the oblate spheroid one :)

    Thanks for everything both of you guys do!
    It was awesome meeting you at Empower. For everyone else coming across this post the has not yet been to an Empower, I highly recommend it.


  • 11.  RE: On Click Counter

    Top
    Contributor
    Posted 06-09-2017 18:24
    It is in Austin next year - I used to live in Austin and it is a great place.


  • 12.  RE: On Click Counter

    Posted 06-09-2017 18:47
    I will definitely be there. Austin is an awesome city.