Forum Discussion

HankHalverson's avatar
HankHalverson
Qrew Cadet
4 years ago

Save and Print a Form

Hello,
I am making a button that will go on a form that will save the data then bring up the print menu. The issue I am running into is that if I add a button that simply says print this record it doesn't work because it is a form and hasn't been saved into a record yet. So I need a button that will save then print. The next thing I tried was to save by redirecting then trying to print but I cannot get that to work because the URL code calls the active RID which is gone once the page has redirected. I am not completely confident in my button/url coding abilities so I could be fundamentally wrong about what is going on but I would appreciate any help to point me in the right direction. 

My code for a formula URL that tries to just print the form:

URLRoot() & "db/" & Dbid() & "?a=printr&dfid=11&rid=" & [Record ID#]
//I don't think the RID exists until the form is saved 

Then my code to redirect the user to save the form to a record:

//formatting visuals of button
var text bgcolor = "#34A853";
var text txtcolor = "white";
var text style = "style=\"text-decoration: none; background:" & $bgcolor & "; border-radius: 5px; padding: 8px 20px; color: " & $txtcolor & "; display: inline-block; font: normal 700 24px/1 \"Calibri\", sans-serif; text-align: center; text-shadow: none;";

//Inner workings of button
var text url =

URLRoot() & "db/" & [_DBID_Project] & "?a=printr&dfid=11&rid=" &[Record ID#]
& "&apptoken=uwi4fb9cj4szcdzjnfxd5xz3te"
& "&rdr=" & URLEncode("https://divisionsinc.quickbase.com/db/brjciz2i6?a=td");

"<a " & $style & " href=\"" & $url & "\">Save and Print</a>"

I couldn't get either of these to work so any help is appreciated. Thanks in Advance!


------------------------------
Hank Halverson
------------------------------
  • I doubt that this can be done in one click because the Record ID# does not exists until the record is saved.

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------
  • UrsulaLlaveria's avatar
    UrsulaLlaveria
    Qrew Assistant Captain
    I found this in the quickbase code samples, may work for you but I don't know for certain. 

    var text rid = 
        If([Record ID#]>0,
            ToText([Record ID#]), // Record ID already exists
            "%%rid%%" // New record, no Record ID exists yet
        )
    ;
    var text url = URLRoot() & "db/" & Dbid() & "?a=er&rid=" & $rid;

    "<a class='Vibrant Primary SaveBeforeNavigating' data-replaceRid=true href='" & $url & "'>Save & Keep Working - Rich Text</a>"

    In your case, you would need to save the record prior to pulling up the print functionality. This would save your record, and then you can use the rdr= to redirect you to the print version. 

    Link to the example: https://resources.quickbase.com/db/bq8mgh24g?a=dr&rid=3206

    ------------------------------
    Ursula Llaveria
    ------------------------------
    • MarkShnier__You's avatar
      MarkShnier__You
      Icon for Qrew Legend rankQrew Legend
      Hank, let us know if this worts!

      ------------------------------
      Mark Shnier (YQC)
      mark.shnier@gmail.com
      ------------------------------
      • HankHalverson's avatar
        HankHalverson
        Qrew Cadet
        First, thanks for the timely responses! So as of now I am working on implementing the code Ursula recommended and I will get back to you guys on if I can get that working. The short term solution I came up with was to put a button in the form that redirected to a dashboard where the user could search and select their record. And each record has its own print button on it. So once they find the desired record there is a print button right there for it and this works because the redirect saves the form creating a record. This is more work for the user and I'd like, so I hope the recommended code works.

        ------------------------------
        Hank Halverson
        ------------------------------