Hello!
I have a code in Google Apps script that I am using in an automation in my app. It is not working, I want to obtain the link of my pdf file, but the column is empty when I trigger the automation.
How can I use a kind of "log message" , I need to see what happens with the script in appsheet, why the link is not written in my column?
Thank you for your help!
p.s. in google apps script in Execution, there is errors: if I activate "return values" - TypeError: Cannot read properties of undefined (reading 'parameter') at doGet(Code:2:20), if I activate "return values" but without give something in "Specific type" - "Name", this error : "TypeError: Cannot read properties of undefined (reading 'fileName') at doGet(Code:2:30)".
Many thanks!
Regards!
Ruxandra
The values for columns of type File and Image are written by the server after the associated file has been uploaded. This upload typically takes a few seconds, so if your script triggers immediately upon the row arriving at the server, it's likely the file upload has not completed yet and so there is no file specification recorded.
Hello!
Yes, google script is the next step in my automation, after the creation of the pdf file. How could I delay the script's execution? I know there is a step "Delay", but the minimum time is 5 minutes which is too much.
Thank you!
Ruxandra
set
Hello!
This is the code:
function doGet(e) {
var fileName = e.parameter.fileName; // Get the file name from the AppSheet request
//var driveId = e.parameter.driveId; // Get the shared drive ID from the AppSheet request
// fileName = "example.pdf"
driveId = "mydriveID"
try {
// Use the advanced Drive service to search for the file
var files = Drive.Files.list({
q: "name = '" + fileName + "' and trashed = false and '" + driveId + "' in parents",
supportsAllDrives: true,
includeItemsFromAllDrives: true,
fields: "files(id, name, webViewLink, parents)"
});
if (files.files && files.files.length > 0) {
var file = files.files[0];
var fileId = file.id;
var filePath = file.webViewLink;
// Get the parent folder name
var folderName = "Root";
if (file.parents && file.parents.length > 0) {
var folder = Drive.Files.get(file.parents[0], {
supportsAllDrives: true,
fields: "name"
});
folderName = folder.name;
}
Logger.log(filePath)
return ContentService.createTextOutput(JSON.stringify({
id: fileId,
name: fileName,
path: filePath,
folder: folderName
})).setMimeType(ContentService.MimeType.JSON);
} else {
throw new Error("File not found");
}
} catch (error) {
Logger.log(error)
return ContentService.createTextOutput(JSON.stringify({
error: "Error: " + error.toString()
})).setMimeType(ContentService.MimeType.JSON);
}
}
Thank you!
Your script request is like:
https://script.google.com/macros/s/your_script_id/exec?fileName=example.pdf
Are you running code on dry?
Hello!
One of my colleague solved the issue using python in/and bigquery. Thank you all for your help!.
Regards!
Ruxandra
That is not a proper appscript file to do the task you want. That function is part of a webapp and cannot be called using an appscript task.
Hello!
One of my colleagues solved the issue using python in/and BigQquery. Thank you all for your help!
Regards!
Ruxandra
How do you create pdf file? From appsheet?
Once pdf file is created (and Saved by appsheet) you can call it from the app.
Your e.parameter.fileName- Is it included in your URL script ?
..../your_script_id/exec?fileName=example.pdf
Hello!
One of my colleague solved the issue using python in/and bigquery. Thank you all for your help!.
Regards!
Ruxandra
IF you just need a script to retrieve a file that has already been created in a Folder in your drive and return the link. This script will take the file name passed from appsheets and the File ID (This can be made static in the script if needed). The function uses sleep and waits 60 seconds. Then goes to the file and subfolders inside it and either matches the file name or based on a partial match as well if you use keys for the name. Then takes the file ID and creates the File URL and returns as a text string to appsheets to be pasted in your row cell of choice. Also lots of loggers to diagnose if needed. I recommend removing the ones that state the file id and folder id when you move to full roll out ๐
Hello!
One of my colleagues solved the issue using python in/and BigQuery. Thank you all for your help!
Regards!
Ruxandra
User | Count |
---|---|
16 | |
13 | |
8 | |
7 | |
4 |