Forum Discussion

JamesDalton's avatar
JamesDalton
Qrew Trainee
5 years ago

Make Formula-URL fields conform to dynamic form rules

Hello, 

I am working on a button that changes statuses from one to the next in a strict order. Most of these statuses were originally linked to dynamic form rules that would allow or disallow a status to be changed based on other factors. For instance, if a user were to choose 'Quote Sent' the user would not be allowed to select that status until a quote record was created. This was all controlled by form rules. I tried adding in a button mentioned above to make it easier for the user and prevent them from choosing a previous status by mistake. The button seemed to work at first, but later it seemed to override the form rules. For example there are messages that are supposed to be displayed informing the user of why they cannot change the status at the time. 

Here is my Formula-URL code and a screenshot of my status field. If there is anything I can do to make this work or if this is impossible, I would appreciate any help. OR is there a way to make Formula-URL fields 'read-only'/disabled?
var text nextStatus = If([Status] = "Pending Initial Action", "Assigned To Underwriter", [Status] = "Assigned To Underwriter", "Quote Sent", [Status] = "Quote Sent", "Awaiting Payment", [Status] = "Awaiting Payment", "Payment Received/Make Live", [Status] = "Payment Received/Make Live", "Policy Live/Money Received", [Status] = "Policy Live/Money Received", "All Appropriate Documents Received", [Status] = "All Appropriate Documents Received", "Policy Documents Sent to Broker");

var text changeStatus= URLRoot()&"db/"&[_DBID_RENEWALS]&"?a=API_EditRecord&rid="&URLEncode([Record ID#])&"&apptoken=d24xdccdwjqg6s9cdce8bq29d8n"&"&_fid_10="&URLEncode($nextstatus);


"javascript:" &
"$.get('" & 
$changestatus & 
"',function(){" &
"location.reload(true);" &
"});" ​



------------------------------
James Dalton
------------------------------
  • Ok, so there's a lot to unpack there, but here are my suggestions:
    1. If your button is to change the status, have the button only available in View mode, rather than in Edit mode. 
    2. Formulas and Form Rules don't really communicate with one another, other than a Form Rule reacting to the value of a Formula.
    3. Start with a new copy of the existing form and set it so that only you/your role use it in View/Edit modes. This benefits you because:
      1. You will be able to make changes on the fly with only your view being impacted
      2. You can remove all the Form Rules that control the Status field and move that logic into the button formula without fear of breaking something
    4. Don't use JavaScript in your buttons. JavaScript has been allowed in Formulas because of a security loophole that is being closed this year. Instead, (if you've followed suggestion #1), you would build your button similarly to this:

    //-----This is an example of an Orange button with White text that checks and immediately un-checks a checkbox
    
    var text chk = "&_FID_34=";    //FID for a checkbox I want to change
    var text tk = "token";         //Apptoken for my application
    
    "<a class='Vibrant Alert' & href=" & 
    
        URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=" & $tk & "&rid=" & [Record ID#] &
        $chk & "1" &
        "&rdr=" &
            
            URLEncode(URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&apptoken=" & $tk & "&rid=" & [Record ID#] &
                $chk & "0" &
                "&rdr=" &
                    URLEncode(URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#]))
    
    
    & ">The Name of My Button</a>"​

    Typically when I use a button to control a field that pushes a record through a strict order of operation (for lack of a better term), I have it setup so that this would be the last action the user takes. So, they would edit the record, making all other changes and once they save the record, I would probably display some message banner saying something like "To Submit Your Work" or "To Complete Your Work, use the 'Submit to [Next Step]' button below". Your banner and the name of the button would change depending on what the current status and next status would be. Below is an example of something similar (though without the banner)

    In this example, the 'Submit to Valuation' and both the bottom red buttons change the status of the record. The 'Start' and 'Submit' buttons are both variable, depending on where in the process this record is.

    ------------------------------
    Blake Harrison
    bharrison@datablender.io
    DataBlender - Quickbase Solution Provider
    Atlanta GA
    404.800.1702 / http://datablender.io/
    ------------------------------