Forum Discussion

GeorgeBramhall2's avatar
GeorgeBramhall2
Qrew Cadet
4 months ago

Create Child Record, Save and then Edit button

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>

 

6 Replies

  • 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. 

    • MikeTamoush's avatar
      MikeTamoush
      Qrew Commander

      Just adding that I get the same behavior. I suspect the code in Magic Buttons is broken. If you find a solution, please post here. I will do the same.

    • MikeTamoush's avatar
      MikeTamoush
      Qrew Commander

      George, are you still having issues? I went back to this, and after all my research, my issue ended up being simple human error. I had my related field number wrong.

      In the below example, my reference field was not 11, and I forgot to update it and it made it hang. All that, and it was a silly typo on my end. Now it works perfect and doesn't hang. Try checking that?

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

  • 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>