Search code examples
google-apps-scriptgoogle-sheetsfile-properties

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


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


Solution

  • 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.