Hey Jeff,
Thank you for getting back to me. Yes, it's actually the same code that is on the linked discussion. It appears you actually got it all to work as well!
Here is the Javascript:
let urlParams = new URLSearchParams(window.location.search);
let dbid = urlParams.get("myDbid");
let recId = urlParams.get('recId');
let myForm = urlParams.get('myFormId');
let usertoken = urlParams.get('usertoken');
let apptoken = urlParams.get('apptoken');
let root = location.protocol + '//' + location.host;
let myURL = `${root}/db/${dbid}?a=API_GetRecordAsHTML&rid=${recId}&dfid=${myForm}&apptoken=${apptoken}`;
let myHostName = "EnterHostName.quickbase.com";
const getURL = () => {
$.post(myURL, {}, function (response) {
$("#dbPagePayload").html(response);
}).then(getDom);
};
const getDom = () => {
let myDoc = document.getElementById("dbFormContainer");
console.log(myDoc);
var opt = {
margin: 1,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().from(myDoc).set(opt).outputPdf('dataurlstring').then(async res => {
var base64result = res.split(',')[1];
var headers = {
'QB-Realm-Hostname': myHostName,
'User-Agent': 'File_Upload',
'Authorization': `QB-USER-TOKEN ${usertoken}`,
'Content-Type': 'application/json'
}
// 59 is my attachment field. Replace it with yours.
body = { "to": dbid, "data": [{"3": {"value": recId}, "59": { "value": { "fileName": "FormPDF.pdf", "data": base64result }} }], "fieldsToReturn": [ 3, 59 ] }
fetch('https://api.quickbase.com/v1/records',
{
method: 'POST',
headers: headers,
body: JSON.stringify(body)
})
.then(async res => {
if (res.ok) {
return res.json().then(res => {
console.log(res)
window.close()
});
}
return res.json().then(resBody => Promise.reject({status: res.status, ...resBody}));
})
.catch(err => console.log(err))
});
};
getURL();
The only two things that were changed on this code was my host name for the variable $myHostName and the attachment field ID. Everything else was left the same
------------------------------
Shane Miller
------------------------------