Forum Discussion

ChyanneEyde's avatar
ChyanneEyde
Qrew Trainee
3 years ago

Magic Button- Createsavecontinue stopped working

Hello! I've been making use of Kirk Trachy's Magic Buttons app - what a treasure! Oddly, I have one button that was working great and then, tho I can't recall making any relevant changes.... now it doesn't work. I'm hoping someone else may be able to catch my error or point out some shift in QuickBase's code pages. 

The button lives on a parent table (which is named Children). When clicked, a new record is created (the records are called Actions). The new record has certain information pre-populated, like a Pupil ID, a School Code, a category. The whole thing has two parts - a Formula URL field and a Code Page. 

None of that is happening right now. Instead, the button leads to a blank page. The URL it creates seems perfect (?), but the page is blank. URL: https://octo.quickbase.com/db/bg8rdt9ai?a=dbpage&pagename=21_1458.html&targetdbid=bq3bzm9za&referencefield=414&rid=17&school=2&category=Individual%20Family&reason=FIS%20Follow-up&apptoken=mqaamebd4cmnrcy9sct2drpa6ky

Part 1, The Field: Formula URL 
//This button appears on the Immediate Needs report, which identifies children whose parents completed a Family Interest Survey and indicated an immediate need.
//Click button to add a new Action record with information from one child pre-populated.

URLRoot()&"db/"&AppID()&"?a=dbpage&pagename=21_1458.html&targetdbid="&[_DBID__21_ACTIONS]&
//the two involved tables, the parent table (Children) and the child table (Actions) are linked by the ref field Pupil Aspen ID.
"&referencefield=414"& //reference field in Actions. Field is named Aspen ID.
"&rid="&[Pupil Number (Aspen)]& //name of key field in Children.
//fields in Action record we want to pre-populate:
"&school="&[School Code - Current School]& //&name of variable constructed in code page .... &[name of field in Children table]
"&category=Individual Family"&
"&reason=FIS Follow-up"&
"&apptoken=mqaamebd4cmnrcy9sct2drpa6ky"

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

Part 2, The Code Page: html 

<!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 school = urlParams.get('school');
const category = urlParams.get('category');
const reason = urlParams.get('reason');
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_19=" + school + "&_fid_226=" + category + "&_fid_399=" + reason, 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#. -->


------------------------------
Chyanne
------------------------------
No RepliesBe the first to reply