Skip to main content
Question

Create Child Record, Save and then Edit button

  • April 18, 2024
  • 0 replies
  • 239 views

GeorgeBramhall2
Forum|alt.badge.img+11

When I press this URL button it just hangs. Any ideas? I am getting this code from Magic Buttons

The button:

URLRoot()&"db/"&AppID()&"?a=dbpage&pagename=createchildsaveandedit.html&targetdbid="&[_DBID_Estimator]&
"&referencefield=11"&
"&rid="&[Record ID#]&
"&apptoken=xxx"

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 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, true);
xhttp.send();
</script>
</body>
 
</html>

 

This topic has been closed for replies.

Forum|alt.badge.img+9
  • Quickbase Alumni
  • April 19, 2024

Can you confirm if a record is actually being created via the addRecord or is the entire page just not doing as intended? Your best bet is to open your browser console and see if you have any syntax or other errors and start there. In all likelihood if it's hung it means that you have an error with something that you would be able to see in your console that is blocking your redirect to the editRecord form of the new entry. 


GeorgeBramhall2
Forum|alt.badge.img+11
  • Author
  • Quickbase Alumni
  • April 25, 2024

The child record does not get created ...getting these errors.

 


GeorgeBramhall2
Forum|alt.badge.img+11
  • Author
  • Quickbase Alumni
  • April 26, 2024

Mistakenly marked as solved.


Forum|alt.badge.img+16
  • Quickbase Alumni
  • May 1, 2024

OK I got closer and know what the issues is, but not how to solve. Anyone know? The code is below. When trying to set the related field to the RID, it fails and hangs. If I remove it, it works as needed, except of course doesn't set the related field so becomes orphaned.

<!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 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&apptoken=" + apptoken + "&_fid_" + referencefield + "=" + rid, true); //This does NOT work
xhttp.open("GET", "https://" + window.location.hostname + "/db/" + targetdbid + "?a=API_AddRecord&apptoken=" + apptoken, true);  //This works but orphans
      xhttp.send();
</script>
</body>
 
</html>