add file property (like jQuery's .data()) to a GDrive file - Google App Script

164 views Asked by At

I was wondering if there's a way to append to a GDrive file some sort of information using Google App Script. For example, I'm currently working on some google Spreadsheets with GAS, and I really need to append to these spreadsheet some useful informations, like "already seen" or "already processed".

I was looking for something like jQuery's .data(), but till now I haven't found anything.

var ss = SpreadsheetApp.openById(spreadsheetId);
ss.data("processed", "true").data("seen", "false")  //--- something like this

Does anyone know if it is possible? Any workaround or trick to accomplish that?

Thank you

3

There are 3 answers

0
BeNdErR On BEST ANSWER

The only solution I found (maybe in the future there will be the possibility to add data to a GDrive file), using GAS, is using the file description to get/set additional info..

// Gets the first document's description.
// Note: This can also be used on a folder
var doc = DocsList.getFilesByType(DocsList.FileType.DOCUMENT)[0];
Logger.log(doc.getDescription());

// This example sets the first document's description
// Note: This can also be used on a folder
var doc = DocsList.getFilesByType(DocsList.FileType.DOCUMENT)[0];
doc.setDescription('My First Doc');
Logger.log(doc.getDescription()); // logs 'My First Doc'

Documentation HERE

I use the description field to store all my info, separated by a pipe. When I need to get a particular file info, I parse the description string looking for what I need.. basically works like a cookie.

1
HDCerberus On

It sounds like what might interest you is Drives custom file properties. You can find more on the methods here. I'm pretty new to programming, and I've never used this particular feature, but I believe it will allow you to specify custom properties for Drive files.

0
rpm On

Currently, it's not possible as you want. There is only one way to set your custom properties using Google Drive Web API for now.