I am encountering an issue with variable insertion in Google Apps Script. I have a script where I'm trying to insert a variable from AppSheet into a text template, but I'm getting "undefined" as the result.
Here's a simplified version of my code:
function createFolderAndGoogleDocInDrive(folderName, abNumber) {
// ... (folder creation and document copying)
// Logging the value for debugging
Logger.log(abNumber["AB nummer"]);
// Extract the value of "AB nummer" from AppSheet and insert it into the content
var abNumberValue = abNumber["AB nummer"];
var content = `
...
AB number : ${abNumberValue}
...
`;
newDoc.getBody().setText(content);
Logger.log("Folder and Google Document created with ID: " + newFolder.getId());
}
What am I doing wrong?
Solved! Go to Solution.
I have changed var abNumberValue = abNumber["AB nummer"];
to
varabNumberValue = abNumber;
Now it works
What TYPE is abNumber in your fuction parameters (folderName,abNumber)?
What do you expect to see in the Log when you use (abNumber["AB nummer"])?
I have a column "AB nummer" with type LongText.
When i fill in for example "12" into the appsheet form I want it to create a document
where it says "AB number : 12"
Here is the whole script:
This is what I get:
I have changed var abNumberValue = abNumber["AB nummer"];
to
varabNumberValue = abNumber;
Now it works
User | Count |
---|---|
18 | |
15 | |
10 | |
7 | |
4 |