Searching for Specific Identifiers Across Multiple Google Apps Script Projects

70 views
Skip to first unread message

Arquivos Mídia

unread,
May 18, 2023, 4:20:19 PM5/18/23
to Google Apps Script Community
Hello everyone,

I've been working on multiple Google Apps Script projects, and I've run into a challenge I'd like some help with.

In my scripts, I use various functions that make API calls. During these calls, I pass various identifiers as part of the payload, one such identifier is " STUDENT  ". Here's an example of what the code looks like:

var options = {
  "method": "post",
  "format": 'JSON',
  "payload": {
    "token": tokenSwa,
    "identificador": "STUDENT",
    "where": where
  }
}


Several of my scripts use this same identifier, and I need to find out which ones are using it. I intend to sweep through all scripts and search for all identifiers. Ideally, I'd like to create a spreadsheet to document which script is using which identifier.

These scripts are not standalone files stored on Google Drive, but scripts attached to documents, so they are visible only in the Google Apps Script manager.

Does anyone have any suggestions on how I can do this efficiently, preferably using Google Apps Script itself?

I appreciate in advance any help you can provide.

cwl...@gmail.com

unread,
May 19, 2023, 6:37:15 AM5/19/23
to Google Apps Script Community
If it were me doing this, I would probably use CLASP and clone all the scripts to my local machine. Then I would use VSCode to do the searching. However, that doesn't answer your question. 
You could first go to the Advanced Drive API reference page to list all your files. On the right side is the "Try this method" sidebar. After some trial and error, I ended up with this query: 
Input boxes (leave all empty except these):
 q      -        mimeType = "application/vnd.google-apps.script"
click on "Show standard parameters" and enter:
fields    -    items(id,title)
(or use this handy url - it may fill it all in for you)  then press Execute and give permission to run under your account.
If all went well, in the lower right should be a Green box with JSON output of all your script files (scriptname and ID). 

From there, you should be able to iterate over each scriptID, get the file, search for your desired parameter, and if found log that scriptID as a positive match. 

If nothing else, that gets you on your way. 

cwl...@gmail.com

unread,
May 19, 2023, 8:06:48 AM5/19/23
to Google Apps Script Community
You can attach this script to a spreadsheet. Create a tab called IDs, (or use your own tabname). (It is slow because it has many write calls. You could speed it up by adding the content to an array, and just pasting the array into the sheet.) Note: You will need to add the Drive (V2) service to your script.

function getScriptIds() {
  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const ws = ss.getSheetByName("IDs")
  try {
    const query = 'mimeType = "application/vnd.google-apps.script"'
    const fieldItems = "items(id,title)"
    let files = Drive.Files.list({
      q: query,
      fields: fieldItems
    })
    for (let i = 0; i < files.items.length; i++) {
      ws.appendRow([files.items[i].title, files.items[i].id]) //this could be sped up significantly,
} //but I assume you will only need to run this once
  } catch (err) {
    console.log('Failed with error %s', err.message)
  }
}

Arquivos Mídia

unread,
May 19, 2023, 8:11:00 AM5/19/23
to google-apps-sc...@googlegroups.com
I greatly appreciate your response, but it seems that the method does not include the files created by containers. The files from the drive do not include the script files that are created inside a container.


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/855411db-0bfe-4613-8c7c-240a8c082f23n%40googlegroups.com.

Arquivos Mídia

unread,
May 19, 2023, 8:13:03 AM5/19/23
to google-apps-sc...@googlegroups.com
Your suggestion sounds perfect, although I have an aversion to using any local support, preferring everything to be in the cloud. That's why I thought about a method that would utilize AppScript itself, but it seems that it's not yet possible.

I will try what you suggested.
Reply all
Reply to author
Forward
0 new messages