KyleRichardson
3 years agoQrew Member
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
------------------------------
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
------------------------------