Forum Discussion
MikeTamoush
12 months agoQrew Elite
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>