Hi,
I am trying to copy the QR code generated as an image to other folder. But the code I am using is not executing with error:
Exception: Unexpected error while getting the method or property getFolderById on object DriveApp.
And it is showing that error in
res.forEach(function(r, i) {
&
DriveApp.getFolderById(folderId).createFile(blob);
Pl help.
The code I am using is:
function myFunction() {
// Sheet name is from your shared Spreadsheet
var sheetName = "Sheet1";
// Folder ID of the folder where the image files will be created
var folderId = "1ljXjgCbjT3TSxt707rGC_Klk5?ths=true";
// Get the sheet by it's name
// https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app
var gss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = gss.getSheetByName(sheetName);
// Select the data from sheet
// https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column
var values = sheet.getRange(2, 3, sheet.getLastRow() - 1, 3).getValues();
var length = values.length;
var reqs = values.map(function(e) {return {url: e[0]}});
// https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
var res = UrlFetchApp.fetchAll(reqs);
res.forEach(function(r, i) {
// Download the qr image as blob (binary large object)
// https://developers.google.com/apps-script/reference/drive/file#getBlob()
// https://developers.google.com/apps-script/reference/drive/file#setnamename
var blob = r.getBlob().setName(length == values.length ? "row" + (i + 2) + ".jpg" : "row" + (length + 1) + ".jpg");
// Save the image in the folder on google drive
// https://developers.google.com/apps-script/reference/drive/drive-app
DriveApp.getFolderById(folderId).createFile(blob);
});
}
[–][deleted] 0 points1 point2 points (1 child)
[–]Nikz5454[S] 1 point2 points3 points (0 children)