@aminsaleh
-
Create a URL for every record in your table.
-
Create a Folder in your Google Drive where the Source of your App lives and name it something like “QR Code PNG”.
-
Add a physical column to your sheet. Maybe name it “QR Code Location”. It should be of Image type. Add this App Formula Concatenate(“/appsheet/data/(Your App ID)/(Your Folder from Step2)/”,CONCATENATE([(Your Key or Whatever you named the QR Code],”.png”))
-
Create a GAS
This is my script. Modify for your use case.
What the script does it gets the URL from my sheet and creates a QR Code and then saves it as a PNG in the “QR Code PNG” folder. The script uses column A from my sheet to name the QR Code when it saves it to the “QR Code PNG”.
function onEdit(e) {
// Column AC index and Sheet name
const targetColumnIndex = 29; // Column AC
const sheetName = ‘(Your Sheet Name)’;
// Check if the edit is on the correct sheet and in column AC
if (e.range.getSheet().getName() === sheetName && e.range.getColumn() === targetColumnIndex) {
const editedRow = e.range.getRow();
const equipmentName = e.range.getSheet().getRange(editedRow, 1).getValue().trim(); // From Column A (Optional)
// Assuming the URL to be encoded in the QR code is in Column AA
const qrCodeUrlData = e.range.getSheet().getRange(editedRow, 27).getValue().trim(); // From Column AA (Your URL column)
// Call the function to generate/update the PNG for this specific row
if (equipmentName && qrCodeUrlData) {
generateOrUpdatePNGForSingleRow(equipmentName, qrCodeUrlData);
}
}
}
function generateOrUpdatePNGForSingleRow(equipmentName, qrCodeUrlData) {
const folderId = ‘(Step2 “QR Code PNG)’; // Target folder ID
const targetFolder = DriveApp.getFolderById(folderId);
// Use the URL from Column AA for the QR code
const qrCodeUrl = “https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=” + encodeURIComponent(qrCodeUrlData);
const fileName = ${equipmentName}.png;
// Delete existing file, if it exists
const files = targetFolder.getFilesByName(fileName);
while (files.hasNext()) {
const file = files.next();
file.setTrashed(true);
}
// Generate and save the new QR code image
try {
const response = UrlFetchApp.fetch(qrCodeUrl);
const imageBlob = response.getBlob().setName(fileName);
targetFolder.createFile(imageBlob);
Logger.log(QR Code PNG generated/updated for ${equipmentName}.);
} catch (e) {
Logger.log(Error generating/updating QR for ${equipmentName}: ${e.toString()});
}
}
-
Create a BOT to call the script.
-
Make sure to add the “QR Code Location” to your detail view.
Explaining steps is not my forte but I hope this works for you or at least points you to the right direction.
I’m working now on printing the QR Code directly from the app to a thermal printer using an iOS device or from a Windows computer. If anyone has a solution for please share it.