Forum Discussion
Hi Aaron,
You'll have to use a code page to accomplish this. QB updated a year or so ago (maybe longer) and removed the workarounds to inject JS directly into a QB record, like the IOL technique. Your URL field could lead you to a code page, which could do all of this for you.
Here's an example of something we implemented:
HTML:
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>EXAMPLE</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://YOURREALM.quickbase.com/db/DBID?a=dbpage&pagename=JS_PAGE.js"></script>
</head>
<body>
<div id="loading">
</div>
</body>
</html>
JS:
const queryString = window.location.search;
urlParams = new URLSearchParams(queryString);
const apptoken = urlParams.get('apptoken')
const mode = urlParams.get('mode')
const rid = urlParams.get('rid')
let tempToken
$(document).ready(function(){
getTempUserToken("TABLEID").then(function() {
let body = {
"to": "TABLEID", // ID of table you're updating
"data": [
{
"3": {
"value": rid
},
"160": {
"value": false
}
}
]
}
$.ajax({
url: 'https://api.quickbase.com/v1/records',
method: 'POST',
headers: {
'QB-Realm-Hostname': 'YOURREALM.quickbase.com',
'Authorization': 'QB-TEMP-TOKEN ' + tempToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(body),
success: function(result) {
alert("ALERT TEXT")
window.history.go(-1) //other, more elegant ways of accomplishing this
},
error: function(result, textStatus, errorThrown) {
alertError(result, textStatus, errorThrown)
}
})
})
})
function alertError(result, textStatus, errorThrown) { // Error function for AJAX calls
alert(textStatus + ': ' + result.responseJSON.message
+ ' - ' + result.responseJSON.description);
}
function closeWindow() {
let newWindow = window.open('', '_self', '');
newWindow.close();
return false
}
/*---------------------------AUTHORIZATION---------------------------*/
let getTempUserToken = async (dbid) => {
let promise = await $.ajax({
url: 'https://api.quickbase.com/v1/auth/temporary/' + dbid,
method: 'GET',
headers: {
'QB-Realm-Hostname': 'YOURREALM.quickbase.com',
'QB-App-Token': apptoken,
'Content-Type': 'application/json'
},
xhrFields: { withCredentials: true },
})
tempToken = promise.temporaryAuthorization
console.log(tempToken)
}
CSS:
#loading {
background: url('https://LINKTOYOURLOADINGGIF.gif') no-repeat top left;
display: block;
position: absolute;
top: 125px;
left: 0;
height: 100%;
width: 100%;
z-index: 9999999;
}
------------------------------
Chris Wheatley
------------------------------
- AaronB2 years agoQrew Trainee
Thanks for the quick response. I had read in several places that direct injects of JavaScript into QB had deprecated but wasn't sure if it was totally or just certain calls.
I am woefully inept at JavaScript so I have some reading to do.Thanks for providing the example code. It will help.
v/r....Aaron
-------------------------------
Update: I put your code into a code page, made a couple minor adjustments....BAM.....it works great.
BIG THANKS!
------------------------------
Aaron B
ab1692@att.com
------------------------------