1

I am creating an invoice system and I am wanting to save the pdfs to google drive.

I set it up so that they would just all save to the same folder. Then I realized that I could make a folder for each individual customer. And by having the script pull the folder ID off of the Client List tab. (See it on column Q of sheet under Client List Tab)

However this means manually making a folder and doing for each new customer. So ideally the script would save each PDF to its own folder based on the name of the customer and create a new folder if there is no folder for that customer.

Is that possible? If so, any pointers to do so? Thanks!

Link for spreadsheet https://docs.google.com/spreadsheets/d/1i3CXHR_EBal5_JAcoKKopNovySzvhmKVCVXXD7K9ke4/edit?usp=sharing

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Welcome to stack, if you have tired to implement this its a good idea to include your code and describe the issues you are having with it. At the very least it would tell us what programming language you are using. – Linda Lawton - DaImTo Nov 26 '21 at 08:24

2 Answers2

0

Assuming you have the client name in variable clientName:

const clients = SpreadsheetApp.getSheetByName('Client List').getDataRange().getValues();
const folders = {};
for (let i = 6; i < clients.length; i++) {
  folders[clients[i][0]] = clients[i][16];
}
let folder;
const id = folders[clientName];
if (id) { folder = getFolderByIdDriveApp.getFolderById(id); }
else { folder = parentFolder.createFolder(clientName); }
idfurw
  • 5,727
  • 2
  • 5
  • 18
  • Where exactly did the author of this question mention they where using Node.js? This question is not going to help them if its not in the programming language they are using. That and you have not bothered to explain what you are doing at all. You may want to consult https://stackoverflow.com/help/how-to-answer – Linda Lawton - DaImTo Nov 26 '21 at 08:18
  • @DalmTo: Just saying: The code snippet above is written in Apps Script, not Node.js. – ziganotschka Nov 26 '21 at 08:56
0

You code can easily handle this.

I am going to assume that you have the customer number. The first thing your code should do would be to do a file.list and using the Q parm as you menotned search for a file with the name of customerNumber and the mime type of application/vnd.google-apps.folder This will give you the file id of that folder.

If it does not exist then you can do a file.create and set the mime type again to 'application/vnd.google-apps.folder'. This response will return you a file id.

Now you have the file id you can upload your file, and set parents to the file id that you just created.

When uploaded your file will be in the directory for that customer.

It is potentially a three step process but it will work.

However this means manually making a folder and doing for each new customer. So ideally the script would save each PDF to its own folder based on the name of the customer and create a new folder if there is no folder for that customer.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449