Forum Discussion

KyleRichardson's avatar
KyleRichardson
Qrew Member
3 years ago

Code Page and URL Formula Field Button Issue

Hello I am trying to get a url formula button, From Magic Buttons, to work to where it creates a child record and opens it in edit mode. I have created a Code Page and URL Formula button field on the desired table. For some reason it keeps coming up with a error every time I try it. Can yall help me figure out whats wrong?

Here is the code for the Code Page

<!DOCTYPE HTML>
<html>

<body>
<script>
const urlParams = new URLSearchParams(window.location.search);
const rid = urlParams.get('rid');
const apptoken = urlParams.get('apptoken');
const targetdbid = urlParams.get('targetdbid');
const referencefield = urlParams.get('referencefield');
const Patient Full Name = urlParams.get('Patient Full Name');
const Patient Email = urlParams.get('Patient Email');
const Patient DOB = urlParams.get('Patient DOB');
const Patient Phone = urlParams.get('Patient Phone');
const Physician Full Name = urlParams.get('Physician Full Name');
const Physician Email = urlParams.get('Physician Email');
const Physician NPI = urlParams.get('Physician NPI');
const Document Type = urlParams.get('Document Type');
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
const response = this.responseXML;
const redirectUrl = "https://" + window.location.hostname + "/db/" + targetdbid + "?a=er&rid=" + response.getElementsByTagName("rid")[0].textContent + "&rl=bbv";
location.href = redirectUrl;
}
};
xhttp.open("GET", "https://" + window.location.hostname + "/db/" + targetdbid + "?a=API_AddRecord&_fid_" + referencefield + "=" + rid + "&apptoken=" + apptoken + "&_fid_6=" + Patient Full Name + "&_fid_8=" + Patient Email + "&_fid_52=" + Patient DOB + "&_fid_10=" + Patient Phone + "&_fid_7=" + Physician Full Name + "&_fid_9=" + Physician Email + "&_fid_51=" + Physician NPI + "&_fid_46=" + Document Type, true);
xhttp.send();
</script>
</body>

</html>


<!-- When you are on a record and you press the button that comes to this page. The button passes the apptoken, rid and target dbid through the button to the page.
This code adds a child record to the targetdbid table and links it back to the parent record.
It then redirects back to that targetdbid table on the record that was just created but in er or edit mode so you can work on the record already
knowing the Record ID#. -->



Here is the Code for the Button Field

URLRoot()&"db/"&AppID()&"?a=dbpage&pagename=createchildsaveandedit.html&targetdbid="&[_DBID_DOCUSIGN_DOCS_JT]&
"&referencefield=28"&
"&rid="&[Record ID#]&
"&Patient Full Name="&[Patient - Full Name]&
"&Patient Email="&[Patient - Email]&
"&Patient DOB="&[Patient - DOB]&
"&Patient Phone="&[Patient - Phone]&
"&Physician Full Name="&[Patient - Doctor - Name]&
"&Physician Email="&[Patient - Doctor - Email]&
"&Physician NPI="&[Patient - Doctor - NPI]&
"&apptoken=b8gyswcbukjqz3duspknhrw6x4f"

// This includes your app's application token and your destination table DBID.
// When you press this button, it passes your targetdbid, referencefield, rid, school, category and apptoken to the code page and the code page first adds a child record with its school and category, captures the id of the record and then places you back on that created record in edit mode. The net affect is it feels like you are adding a record but you already have and now you have the record id.

------------------------------
Kyle Richardson
------------------------------
  • Try this approach as a Formula Rich Text field type

    The code below work to add a record and then blend the user on the newly added record in edit mode.
    var text RID = "%%rid%%";

    var text AddShipment = URLRoot() & "db/" & Dbid() & "?a=nwr";
    var text EditShipment = URLRoot() & "db/" & Dbid() & "?a=er&rid=" ;

    var text URL =
    $AddShipment
    & "&rdr=" & URLEncode($EditShipment) & $RID;


    "<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #4b7097; border-radius: 5px; color: #ffffff; display: inline-block; padding: 0px 0px 0px 0px; width:100px; text-align: center; text-shadow: none; border: 2px solid #030404; font-size: 12px \"href='"
    & $URL
    & "'>Save and Display in Edit Mode</a>"

    NOTE: The %%RID%% does not seem to like being URLEncoded.

    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------
    • KyleRichardson's avatar
      KyleRichardson
      Qrew Member
      I appreciate the suggestion.  I tried it out and it gives me the error that the Parent Record is Not found.  Is that formula supposed to be used on the parent record to open and edit the child record?

      ------------------------------
      Kyle Richardson
      ------------------------------
    • KyleRichardson's avatar
      KyleRichardson
      Qrew Member
      This is what I ended up putting in.  Please let me know what I did wrong.

      var text RID = "%%rid%%";

      var text AddDocusignDocJT = URLRoot() & "db/" & Dbid() & "https://companyname.quickbase.com/db/bsaxb9zdy";
      var text EditDocusignDocJT = URLRoot() & "db/" & Dbid() & "https://companyname.quickbase.com/db/bsaxb9zdy";

      var text URL =
      $AddDocusignDocJT
      & "&rdr=" & URLEncode($EditDocusignDocJT) & $RID;


      "<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #4b7097; border-radius: 5px; color: #ffffff; display: inline-block; padding: 0px 0px 0px 0px; width:100px; text-align: center; text-shadow: none; border: 2px solid #030404; font-size: 12px \"href='"
      & $URL
      & "'>Save and Display in Edit Mode</a>"

      ------------------------------
      Kyle Richardson
      ------------------------------
      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend
        Can you clarify your desired workflow?  Are trying to put the user on a Add Record form to do data entry and have them save but end up back in edit mode?

        ------------------------------
        Mark Shnier (YQC)
        mark.shnier@gmail.com
        ------------------------------
    • KyleRichardson's avatar
      KyleRichardson
      Qrew Member
      I was actually able to get my original formula to work.  Thank you for your insight and options.

      ------------------------------
      Kyle Richardson
      ------------------------------