why hiderow() script not working for editors

112 views
Skip to first unread message

Saman Plast Arya

unread,
Sep 14, 2021, 9:00:33 AM9/14/21
to Google Apps Script Community
Hi
I have below script for my IN-OUT sheet:

function onEdit(e) 
{
  const sh=e.range.getSheet();
  const shts=['IN-OUT'];
  if(shts.indexOf(sh.getName())!=-1 && e.range.columnStart==10 && e.value=="TRUE") 
  {
    e.range.setValue("FALSE");
    sh.hideRows(Number(e.range.rowStart));
  }
}

its working well for me. when i tick checkbox the current row hide. but for editors which i shared this sheet to them it is not working.

would you please some body help me to correct the code

thanks

CBMServices Web

unread,
Sep 14, 2021, 12:41:16 PM9/14/21
to google-apps-sc...@googlegroups.com
Hi Saman,

Each editor must go through the authorization to allow the script to run for his account. 

Probably easiest way to do this is to ask each editor to open the script editor and try to manually run the onEdit function. That will cause the pop-up for them to approve the authorization. Script will fail because you are using environment variables that are not available when run manually but after the authorization the script will function for them.

Another way to do this is create a new function and tie it to a menu command to have them run it and get the authorization pop-up.

--
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/d6cd602e-080d-479e-8204-c74a7a474096n%40googlegroups.com.

Saman Plast Arya

unread,
Sep 17, 2021, 10:59:07 AM9/17/21
to Google Apps Script Community
Hi George,

Thank you very much for your reply,

I did your solution but nothing has changed. 
It seems the function is working well because I added  below code to my function and message appears well for me and who I shared this sheet to them as editors but the row which should be hide for me as owner but didn't hide for shared persons. 

check my new code :

function onEdit(e) 
{
   const sh=e.range.getSheet();
   const shts=['IN-OUT'];
   if(shts.indexOf(sh.getName())!=-1 && e.range.columnStart==10 && e.value=="TRUE") 
 {
    sh.hideRows(Number(e.range.rowStart));
    e.source.toast('Row' + e.range.rowStart + ' will be hide now');
  }
}

Can you check my code and give me you solution?

Regards,
Saman



CBMServices Web

unread,
Sep 17, 2021, 3:01:13 PM9/17/21
to google-apps-sc...@googlegroups.com
Hi Saman,

 Here is how I would code it:

function onEdit(e
{
   const sh=SpreadsheetApp.getActiveSheet();
   const row = e.range.getRow();
   const col = e.range.getColumn();
   if(sh.getName()=="IN-OUT" && col==10 && e.value=="TRUE"
 {
    sh.hideRows(row);
    e.source.toast('Row' + row + ' will be hidden now');
  }
}

But I checked yours out and it worked correctly to hide the relevant row. I also shared the spreadsheet with another account I have and it worked correctly.

Only thing left that I can think of is if workspace admin restrictions are causing you difficulties. Is this a regular gmail account or a business account?

If it is a managed business account, check with the administrator controls. perhaps something is blocking the execution on those accounts.


Saman Plast Arya

unread,
Sep 18, 2021, 3:10:17 AM9/18/21
to Google Apps Script Community
Hi George

Thank you for your reply,

I checked my account and it is not business. also i checked the code and i found that the problem is related to that i have protected some columns in my sheet and when i remove all protections its working well. you can check it yourself in your code and see the hide will not work when you do some protection on columns . i could not remove my protection because some of my columns have arrayformula and should be protected and when shared editors tick the checkbox in column 10 the whole row hide.

CBMServices Web

unread,
Sep 18, 2021, 12:56:50 PM9/18/21
to google-apps-sc...@googlegroups.com
Hi Saman,

Yes protecting any cell would prevent them from making any changes including hiding it. 

There is not much you can do here besides maybe making your own protection of the cells via onEdit check where is they change those cells, you warn them not to and then revert content changes.


Suresh Kumar

unread,
Oct 10, 2022, 7:10:10 AM10/10/22
to Google Apps Script Community
Hi all, 

Even I am facing the same issue. I have one onedit trigger its not working for editors. I have corporate work account. I have two tabs in my google sheet and I (owner) protected one sheet.  I tried the script by giving permissions in editor account but still not working.

Help me if any one resolved this

Reply all
Reply to author
Forward
0 new messages