On Click Counter

  • 0
  • 1
  • Question
  • Updated 9 months ago
  • Answered
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.
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb

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.

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,634 Points 50k badge 2x thumb
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.
 
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
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.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,634 Points 50k badge 2x thumb
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);"
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
Trying this now.
Thanks Mark!
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
It worked. I just needed to add the apptoken to it.
Thanks Mark!
Photo of Carlos

Carlos

  • 796 Points 500 badge 2x thumb
Absolutely off topic, but are there other colors for jGrowl? Haven't managed any other than the "theme: 'jGrowl-green'"
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb

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

Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
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.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,064 Points 20k badge 2x thumb
It is in Austin next year - I used to live in Austin and it is a great place.
Photo of @lin

@lin

  • 840 Points 500 badge 2x thumb
I will definitely be there. Austin is an awesome city.

This conversation is no longer open for comments or replies.