Skip to main content
Question

On Click Counter

  • June 9, 2017
  • 0 replies
  • 113 views

Forum|alt.badge.img+6
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.
This topic has been closed for replies.

  • Quickbase Alumni
  • June 9, 2017

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.


Forum|alt.badge.img+6
  • Author
  • Quickbase Alumni
  • June 9, 2017
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.

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.
 

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);

  • Quickbase Alumni
  • June 9, 2017

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


Forum|alt.badge.img+6
  • Author
  • Quickbase Alumni
  • June 9, 2017
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.