Forum Discussion

AidonOlligschla's avatar
AidonOlligschla
Qrew Cadet
4 months ago

Dynamic-Displaying Button in One Field

Hello All,

Wondering if anyone knows how to get creative here - I'd like a dynamic button within a singular column (field) of a report.  This way, depending on the conditions, the button changes based on the next predicted behavior.  Here's my situation:

  • If the parent record does not have a related child record, display blue "Request Change" button.
  • If the parent record does have a related child record, display green "Edit Request" button.

I understand this would be easy to accomplish by using two separate button fields, but the idea is to keep it clean and predictable.  Any ideas?  Picture for reference...



------------------------------
Aidon Olligschlager |
Flight Operations Technical Support
Pentastar Aviation
Waterford MI
aolligschlager@pentastaraviation.com | 248-202-9587
------------------------------

7 Replies

  • Make sure that it's a formula rich-text field and then the following will get you set: 

    var text url = configure what you want the button to do with if statements here;

    var text button = "<a href='" & $url & "' class='Vibrant SaveBeforeNavigating' style='background: " & if( //insert if condition here to color the button ) & "'>" & if(//insert condition for what you want the button label to be) & "</a>"



    ------------------------------
    Chayce Duncan
    ------------------------------
    • AidonOlligschla's avatar
      AidonOlligschla
      Qrew Cadet

      Good Morning Chayce,

      Here's what I've put together so far and I'm getting an error of "a variable declaration must end with a semi-colon."

      var text url = If([Any Requests] = null,

      URLRoot() & "db/" & [_DBID_REQUESTED_CHANGES] & "?a=API_GenAddRecordForm&_fid_10=" & URLEncode ([QB Unique Field])& "&z=" & Rurl(),    //if no requests already, add request
              
      URLRoot() & "db/" & [_DBID_REQUESTED_CHANGES] & "?a=s&query={%2710%27.TV.%27" & URLEncode([QB Unique Field]) & "%27}&opts=disprec" & "&apptoken=xxxx" & "&z=" & Rurl()      //if already a request, edit request
              
              );    //if no requests already, add request

      var text button = "<a href='" & $url & "' class='Vibrant SaveBeforeNavigating' style='background: " & if([Any Requests] = null, "#81c6e3") & "'>" & if([Any Requests] = null, "REQUEST CHANGE") & "</a>"



      ------------------------------
      Aidon Olligschlager |
      Flight Operations Technical Support
      Pentastar Aviation
      Waterford MI
      aolligschlager@pentastaraviation.com | 248-202-9587
      ------------------------------
      • ChayceDuncan's avatar
        ChayceDuncan
        Qrew Captain

        It looks like you're not closing out the variable button and actually declaring it. See if this works: 

        var text url = If([Any Requests] = null,

        URLRoot() & "db/" & [_DBID_REQUESTED_CHANGES] & "?a=API_GenAddRecordForm&_fid_10=" & URLEncode ([QB Unique Field])& "&z=" & Rurl(),    //if no requests already, add request
                
        URLRoot() & "db/" & [_DBID_REQUESTED_CHANGES] & "?a=s&query={%2710%27.TV.%27" & URLEncode([QB Unique Field]) & "%27}&opts=disprec" & "&apptoken=xxxx" & "&z=" & Rurl()      //if already a request, edit request
                
                );    //if no requests already, add request

        var text button = "<a href='" & $url & "' class='Vibrant SaveBeforeNavigating' style='background: " & if([Any Requests] = null, "#81c6e3") & "'>" & if([Any Requests] = null, "REQUEST CHANGE") & "</a>";

        $button



        ------------------------------
        Chayce Duncan
        ------------------------------
  • AlexWilkinson's avatar
    AlexWilkinson
    Qrew Assistant Captain
    Aidon,

    Here's an example of how I handle similar needs for "conditioned" buttons - one which take various actions and have various wording or styling depending on other fields on the record.



    In this example, the user will be able to add a contact where the record has data about a new person (e.g., a new, unrecognized email) and about an organization whose web-domain is either know to the app or not known. Accordingly, the button displays on a report either as "Add Person to KNOWN Organization" or "Add Person to NEW Organization".

    The button uses a URL computed as a var in portions of the formula field not shown in the screenshot above. It also uses custom styling that is defined in app-wide variables (the three "[customButton...]" variables. This is a convenience to make it easier to standarding the app's buttons without constant cut-and-paste.

    Alex Wilkinson

    Alex


    • AidonOlligschla's avatar
      AidonOlligschla
      Qrew Cadet

      Gentlemen,

      Thank you for your insight.  I've been getting into the magic URL buttons recently and it's amazing how you can reduce workflows down to a single click.  Looking forward to using these more.

      Best,



      ------------------------------
      Aidon Olligschlager |
      Flight Operations Technical Support
      Pentastar Aviation
      Waterford MI
      aolligschlager@pentastaraviation.com | 248-202-9587
      ------------------------------