Button to toggle a checkbox in report

  • 0
  • 1
  • Question
  • Updated 7 months ago
  • In Progress

I have a report with a checkbox.  I would like to create a button on the report that would toggle the checkbox on or off, depending on it's current status.  I would like the toggle button to change labels (ie. True or False) based on the current value of the checkbox.  Finally, I'd like to have the report stay on the screen.  It can refresh, but I'd prefer it to remain at the report. 

This seems to be beyond my skill level.  Can anyone help me create this?

Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
Like this?

Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb

My current issue is that the button does not seem to work consistently.  It will toggle the checkbox the first time I click it, but will not toggle it on subsequent clicks.  Below is my code.  Any Ideas?
 
var text XXX = If([MD Approval (2)]=false,"true",
[MD Approval (2)]=true,"false");

var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_87=" & $XXX & "&apptoken=XXXXXXXXXXXXXX";

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

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
either of these will work. The issue is that true and false are not text strings, they are boolean so they do not go in quotes.

var text XXX = If([MD Approval (2)]=false, true, false);

var text XXX = not [MD Approval (2)];
Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb
I had to change the "var text XXX" to "var bool XXX", otherwise it kept popping an error.  But this still doesn't solve my issue.  I hit the button and it toggled the checkbox.  I tried again and it toggled it successfully, third, fourth and fifth, it did not. 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
Can you post your complete code.  It should work.
Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb

Here you go.

var bool XXX = not [MD Approval (2)];

var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_87=" & $XXX & "&apptoken=XXXXXXXXXXX";

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

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
see if this works for the javascript

"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});"
Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb

Yeah, it didn't like that.  When I replaced my javascript code with this, I got a blank page that just says "[object Object]". 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
I tested this and could not get it to fail.  I'm not sure  what else to suggest.  Any chance you were clicking too fast before the page got a chance to refresh

var bool XXX = not [checkbox];

var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_26=" & $XXX ;

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

Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,184 Points 20k badge 2x thumb
The XXX user defined variabvle is evaluated only once so only the first toggle works.

There might be a native solution but there certainly is a script solution.

Unfortunately I am about to shut down for the weekend. Have a good one yourself.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
Dan, in my experience, the button code is refreshed when the record refreshes, right?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,184 Points 20k badge 2x thumb
I will follow up later. I answered in haste and have to double check what I wrote!
Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb
It still seems to stop toggling the checkbox on the 3rd click.  I have even waited a few mins and tried gain to confirm that there is no timing issue.  No luck.  Is there another way to approach this?  I need a simple way for my manager to remove a record from his view. 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
Are you trying to refresh a particular report after each click?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
You can use this syntax

Define URLONE as the code to update the checkbox.

Define URLTWO as the report.

$URLONE
& "&rdr=" & URLEncode($URLTWO)
Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb
Yes, the button displays in a report and I would like the report to refresh. 
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
So URLONE would be this

var bool XXX = not [MD Approval (2)];

var text URLONE=
URLRoot() & "db/" & Dbid () & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_87=" & $XXX & "&apptoken=XXXXXXXXXXX";

var bool XXX = not [MD Approval (2)];

var text URLTWO=
URLRoot() & "db/" & Dbid () & "?a=q&qid=xx;

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

Fill in xx with the report id#
Photo of Todd Griffith

Todd Griffith

  • 220 Points 100 badge 2x thumb
Whooooooot!!!    This seemed to have worked.  I hit the button 20 times and it worked every time.  Thanks for sticking with me and the great help!!!!
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
Thx for letting me know.it worked.
Photo of Michael Halbreiner

Michael Halbreiner

  • 230 Points 100 badge 2x thumb
I'm trying the same thing with a slightly different take with a pop up display after clicking.  However, The button is not toggling the checkbox field.  Below is my code:

var bool NewToggle = If ([Toggle Submit] = true, false, true);

var text URL = URLRoot() & "db/" & "?act=API_EditRecord&rid=" & [Record ID#] & "&_fid_214=" & $NewToggle & "apptoken=jzbh5tctc9cbhb5dkskndwjcgca";

"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"$.jGrowl('Your project proposal has been submitted', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"


fid_214 is the [Toggle Submit] field.  not sure where i'm going wrong.  

Thanks
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 69,894 Points 50k badge 2x thumb
The problem  is here
& "apptoken=jzbh5tctc9cbhb5dkskndwjcgca";
& "&apptoken=jzbh5tctc9cbhb5dkskndwjcgca";


The trick to debugging that is to do this, which I suggest that you do before correcting the bug so you learn how to debug.

Comment out the javascript stuff and just run the URL



var bool NewToggle = If ([Toggle Submit] = true, false, true);

var text URL = URLRoot() & "db/" & "?act=API_EditRecord&rid=" & [Record ID#] & "&_fid_214=" & $NewToggle & "apptoken=jzbh5tctc9cbhb5dkskndwjcgca";


$URL

//"javascript:" &
//"$.get('" & 
//$URL & 
//"',function(){" &
//"$.jGrowl('Your project proposal has been submitted', {life: 5000, theme: 'jGrowl-green'});" &
//"});" &
//"void(0);"


That will expose the error message which will be complaining about missing app token, and then that would been a clue for you about the missing &

Photo of Evan Martinez

Evan Martinez, Community Manager

  • 11,998 Points 10k badge 2x thumb
Hi Todd,

Another alternative that might be helpful for checking the status of the checkbox is to instead use the numeric value that the checkbox fields utilize. 1 for True and 0 for false. So something like. 

var numeric XXX = If([Checkbox]=1, 0,1);

var text URL =
URLRoot() & "db/" & Dbid () & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_26=" & $XXX ;

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

That way you are pushing the numeric value into your checkbox field to request the change which might process differently from the not syntax.