At the moment, I am utilizing a Google script that runs periodically on my Gmail account to retrieve all attachments labeled according to certain criteria. The issue arises when trying to access attachments within a folder located on a shared drive using the getFolderByName
method in Google Sheets.
After exploring various forum discussions, it became evident that leveraging the Drive API is essential for accessing folders on shared drives. Consequently, I aim to fetch the folder ID from my Google Sheet rather than relying on getFolderByName
.
The following are three key functions:
getLibelleConfigs
: Retrieves LibelleConfig objects from the configuration sheetgetFolderFromPath
: Obtains or creates a folder based on its pathgetOrCreateFolder
: Retrieves an existing folder or creates a new one
function getLibelleConfigs() {
// function code here
}
function getFolderFromPath(path) {
// function code here
}
function getOrCreateFolder(folderName, parentFolder) {
// function code here
}
Google Sheets excerpt:
+----------------+-----------+
| LABEL | ID FOLDER |
+----------------+-----------+
| example@email.com | xxxxx_1 |
| another@example.com | xxxxx_3 |
| test@test.com | xxxxx_1 |
| demo@demo.com | xxxxx_2 |
+----------------+-----------+
Edit
function saveAttachmentsFromLibelleConfig(libelleConfig, messageIdHistory) {
// function code here
}
My Solution :
function movefileToSharedDrive() {
// function code here
}
function makeCopy(srcFolderId, dstFolderId) {
// function code here
}
function deleteFiles(folderId) {
// function code here
}
The process involves triggering attachment extraction to my drive, copying to the shared drive, and deleting files from my drive to prevent duplicates.