URL Button to check/uncheck a check box

  • 1
  • 2
  • Question
  • Updated 1 year ago
  • Answered
Is it possible to use conditional logic with an api call? I would like to create a URL button to check or un-check a checkbox depending on the state it is in 
Photo of Jordan

Jordan

  • 1,574 Points 1k badge 2x thumb

Posted 1 year ago

  • 1
  • 2
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,758 Points 5k badge 2x thumb
Hi Jorden,

Yes, you can.

Please have a look at the sample formula:

URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
	& If([Checkbox]=true, "&_fid_101=0", "&_fid_101=1")
	& "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#])

Replace _fid_101 with your field Id and [Checkbox] field with your checkbox field name.

Please let me know if this works for you and need any further help.

Thanks,

Gaurav
Photo of Jordan

Jordan

  • 1,574 Points 1k badge 2x thumb
This did the trick, although it does redirect you into the record, I should have been more clear, I am wanting to do this from a table view
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,758 Points 5k badge 2x thumb
Jordan,

Please have a look at the Mark Answer. He did the exact thing which you are asking. Also, that formula will work in all your scenarios whether you are triggering from the table or form it will redirect back to your original position. 

Please go ahead with that.

Thanks,
Gaurav
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,546 Points 50k badge 2x thumb
No Problem

Here is an example of a URL Formula field

var text NewCheckboxValue = IF([Status]="New","0","1");


var text URL= URLRoot() & "db/" & [_DBID_TABLE_1] & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_7=" & $New Status
& "&apptoken=" & "XXXX";

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

That last stuff is just boilerplate code (as long as you name your formula variable URL) which refreshes the page.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,546 Points 50k badge 2x thumb
Jordan, my solution will refresh the page you were on, be it a record or a report.
Photo of Jordan

Jordan

  • 1,574 Points 1k badge 2x thumb
I am struggling to get this solution to work, 

I am currently using 

var text NewCheckboxValue = If([Priority]="New","0","1");

var text URL= URLRoot() & "db/" & [_DBID_TASK] & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_32=" & $New Priority;

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

Gaurav Sharma

  • 5,756 Points 5k badge 2x thumb
Use this:
var text NewCheckboxValue = If([Priority]=True,"0","1");

var text URL= URLRoot() & "db/" & [_DBID_TASK] & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_32=" & $NewCheckboxValue;

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

Gaurav Sharma

  • 5,756 Points 5k badge 2x thumb
Replace that with the Dbid()
Photo of Jordan

Jordan

  • 1,574 Points 1k badge 2x thumb
This did the trick, thank you guys!
Photo of Gaurav Sharma

Gaurav Sharma

  • 5,756 Points 5k badge 2x thumb
Cheers!
Photo of Khoi Nguyen

Khoi Nguyen

  • 60 Points
What did you replace with Dbid()?