Forum Discussion
That probably would work if I knew Javascript. As it is, all I can try to do is modify the existing code page which I have tried and failed miserably. Turns out you can't really just guess your way through a programming language :)
------------------------------
Mike Tamoush
------------------------------
Actually that wont work. The problem is I am not on the parent record when it is 'saved'.
I am on a grandparent (though, at the time of the button push, it is not a parent or grandparent, it is a single record). I push a button and it runs the AddRecord API, adding a child. I want to delay, and then land on this child. I would need to somehow pass the RID of the new child.&disprec=1 performs some sort of magic that auto displays the newly created record. I would somehow need to know what magic it performs, and pass that magic into the code page.
Though it did just dawn on me, i can look up the max record id in the child table, and navigate to 1 more than that.....if I can figure out how to pass that +1 record ID to the code page....ill try it.
Update - I am not good enough at javascript to modify the code page, but I suspect my idea would work. But, i would need a parent table to get the max record id and pass it back through, which i can do but is a bit annoying...not sure there are any other solutions though.
------------------------------
Mike Tamoush
------------------------------
- ChayceDuncan2 years agoQrew Captain
The Max Record ID# would probably only work if the child creation is sequential no? Can you guarantee that the new grandchild is sequenced correctly? From your description the easiest and best solution is still javascript where by instead of having your current button create the record - you move it to a code page, add the record, get the response back and then redirect the user. The best I can offer is some generic functions though that would get you moving:
const tempToken = (dbid) => {return new Promise((resolve,reject) => {var headers = {'QB-Realm-Hostname': 'your realm name','QB-App-Token': 'your app token,'Content-Type': 'application/json'}fetch(`https://api.quickbase.com/v1/auth/temporary/${dbid}`,{method: 'GET',headers: headers,credentials: 'include'}).then(res => {if (res.ok) {return res.json().then(res => resolve(res.temporaryAuthorization));}return res.json().then(resBody => reject({status: res.status, ...resBody}));}).catch(err => reject(err))})}const upsert = (token) => {return new Promise((resolve,reject) => {var headers = {'QB-Realm-Hostname': 'your realm name','Authorization': `QB-TEMP-TOKEN ${token}`,'Content-Type': 'application/json'}var body = {to: 'target dbiddata: [{"field": { value: ""},"field": { value: ""},"field": { value: ""},}],mergeFieldId: commit.mergeFieldId,fieldsToReturn: [3]}fetch('https://api.quickbase.com/v1/records',{method: 'POST',headers: headers,body: JSON.stringify(body)}).then(res => {if (res.ok) {return res.json().then(res => resolve(res));}return res.json().then(resBody => reject({status: res.status, ...resBody}));}).catch(err => reject(err))})}//invoke functionstempToken("").then((token) => {upsert(token).then((res) => {var newRid = res.metadata.createdRecordIds[0]window.location.replace("/dbid/?a=dr&rid=" + newRid)})})
------------------------------
Chayce Duncan
------------------------------- MikeTamoush2 years agoQrew Elite
Thanks Chase. I think the Max Record ID would work because, lets say this is the scenario:
I am on a record in Table A (Table A has many Table B). I want to push a button while on Table A, have it create a record in table B, delay for a second, then land on that newly created record in Table B.
If the user is on Table A, and the current max record ID in table B is 100, when they push the button it will have to be 101. It doesn't matter what the max child is, I want the max record ID in that entire table (which I can get using a psuedo parent table etc). So I can redirect to that max record ID. Maybe you can help though.
I am using an existing code page. See below for how it returned normally, and how I am trying to get it to return. Can you spot my issue?
My rich text button includes this:
var text RID = ToText([Maximum Record ID#]+1);
var text Pause =
URLRoot() & "db/" & "bpu98ejpu" & "?a=dbpage&pageid=61"
& "&returndbid=bry7tkmnx"
& "&rid=" & $RID ;My code page snip:
const rid = urlParams.get('rid'); //I added these 3 constants. Not in original code
const returndbid = urlParams.get('returndbid');
const rl = prevUrlParams.get('rl');}
function errRdr(){
// Redirects to the previous page, if this page was the previous page as well, then redirect to the app home page
if(document.referrer && document.referrer !== window.location.href) {
// window.location.href = document.referrer; //this was working code
window.location.href = "https://" + window.location.hostname + "/db/" + returndbid + "?a=dr&rid=" + rid + "&rl=" + rl; //i changed to this
}else{// window.location.href = window.location.origin + window.location.pathname; //this was working code
window.location.href = "https://" + window.location.hostname + "/db/" + returndbid + "?a=dr&rid=" + rid + "&rl=" + rl; //i changed to this
}
}
------------------------------
Mike Tamoush
------------------------------- ChayceDuncan2 years agoQrew Captain
Ah - I see what you mean on the max rid. In that case in theory it could work.
In regards to the code - I copied the snippet but it seems to be incomplete / has syntax issues. Can you elaborate on what the main issue is or provide more code?
------------------------------
Chayce Duncan
------------------------------