Best answer

Google Drive - get new filename after rename

  • 2 September 2019
  • 7 replies
  • 650 views

Userlevel 3
Badge

I have multiple copies of a Google Sheet (my template), with various cell protections. Those sheets are shared and used once – they are left untouched after use for archival purposes.

Whenever someone uses the file, they rename it with a customer name and address, for later searching. The renaming is done after the file is changed.

What I want to do is to have Zapier monitor file updates and send me an email or some other action, with the new filename. When Google Drive's Updated File triggers, Zapier receives the current filename (my template name).

How could I get the new file name after X minutes, using the file_id? Find File action expects a filename, not the file_id. Any ideas?


icon

Best answer by PaulKortman 22 November 2019, 02:59

View original

7 replies

Userlevel 5

Hi @Martinewski — When someone uses the file and then renames it, are they renaming the original file? Or are they making a copy of the file, changing it, and then renaming it?


Userlevel 3
Badge

I have a Zap that creates a copy of a template file before this. So, they're actually renaming the original file (which is not my template file, but a copy of it).


Userlevel 7
Badge +12

Hi @Martinewski! I wanted to swing back round on this to see if we can find you an answer.

Could I trouble you to clarify your last comment a little? You said that folks are renaming the original file, which is a copy, so I'm a little unclear.

Is this what's happening:

  1. You have a template file (File A)
  2. A Zap runs to make a copy of the template file (FILE 😎, that then becomes the new template
  3. The original 'template' file (FILE A) is then used as the file that's worked in
  4. When the updated file Zap runs, it's giving you the original name FILE A and not the updated name

Is that right?


Userlevel 5

Thanks for following up on this, @Danvers — I read the reply comment, but didn't have time that day to dig in further, and then clearly it slipped my mind. 😩

My read of this was slightly different than yours (if I'm understanding your correctly), however. I took it to mean that at Step 3, it would be FILE B that is then used as the file that's worked on. But then I got lost completely as to what was triggering the "Updated File" Zap.


Userlevel 7
Badge +12

Hi @Martinewski! Are you still looking for some help with this? If so, could I trouble you to clarify what you are looking to do? Thanks!


Userlevel 3
Badge

Hey, sorry for the delay.

I have a Google Sheet A, which is copied to Google Sheet B. File A never changes, it's my template file. File B is created using a default filename.

When someone is going to use file B, they rename it. I need to receive this new filename.


Userlevel 7
Badge +10

@Martinewski This is a perfect use case for a Google Apps Script. You can create a webhook (doGet) and take the file ID from the webhook URL and get the file name and return it as a result. There are a bunch of examples of this on stackoverflow etc. what follows is theory code for Google Apps script, this is not tested and may error ... but it should get you started:

function doGet(e){

  var ss=SpreadsheetApp.openById(e.parameter.sheetid);

  var ssName = ss.getName();

  var NameJSON = {'FileName':ssName, 'FileID': e.postData.sheetid}; 

  return ContentService.createTextOutput(JSON.stringify(NameJSON) ).setMimeType(ContentService.MimeType.JSON); 

}

then publish the script and it will give you a URL to call via a zapier webhook (GET) step be sure to add ?sheeetid=(the-file-id) to the end of the URL where you replace (the-file-id) with the actual ID of the file. This will return the file name to the webhook step in Zapier. .


Let me know if you need more help with this.


Reply