Forum Discussion

JordanBeatty1's avatar
JordanBeatty1
Qrew Captain
8 years ago

URL Button to check/uncheck a check box

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 
  • 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
    • JordanBeatty1's avatar
      JordanBeatty1
      Qrew Captain
      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
    • GauravSharma3's avatar
      GauravSharma3
      Qrew Commander
      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
  • 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.
  • Jordan, my solution will refresh the page you were on, be it a record or a report.
  • 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);
    • GauravSharma3's avatar
      GauravSharma3
      Qrew Commander
      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);