Open Google Drive document and apply filters

1

Hello,

I started using Google Drive to make it easier to share documents between the various departments of the company, but I do not know how to create "Macros".

I would like to have a MENU file where the various departments are located and through the link they open the same General file but with filters depending on the department that opened it.

Example:
The Commercial Department opens the MENU and clicks the Commercial button and the General File opens. (So far I've been able to do and it works)

//Abrir Ficheiro
function AbrirComercial() {
var page =
 '<script>window.open("https://docs.google.com/spreadsheets/xxxxxxxxx"); google.script.host.close()</script>';

var interface = HtmlService
.createHtmlOutput(page)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(1)
.setHeight(1);   
SpreadsheetApp.getUi().showModalDialog(interface, 'Abrindo... ');
}

What I can not do is run the filters after opening the General File.

If you open the file and run the function everything runs fine but what I want is that after opening the General File the following filters will be applied.

//Filtrar Comercial
{ var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('C4').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['', 'Consumiveis', 'Direcção Financeira', 'Direcção Geral', 'Electricidade', 'Expansão', 'Financeiro', 'Limpeza', 'Manutenção', 'Manutenção Armazém', 'Manutenção Armazéns', 'Operações', 'Patrimonio', 'Procurement', 'Responsabilidade Técnica', 'RH', 'Segurança', 'Serviços Centrais'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(3, criteria);

 //Filtro Activos  
spreadsheet.getRange('J4').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.setHiddenValues(['#N/D', 'Desactivo'])
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(10, criteria);  
};

Is there a way to run script while the page loads to only then run the filters?

Thank you.

    
asked by anonymous 05.12.2018 / 16:59

0 answers