I want to filter a google sheet for one value only, as in this question/answer.
I have activated sheets-api and looked through documentation, how to add oauth2 verification. Concluded, that it should happen automatically, since the script is container-bound.
var ss = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(ss.getSheetByName('Aufgaben')); // change active sheet
var filterCriteria = {"type":"TEXT_CONTAINS","values":[{"userEnteredValue": "0001" }]}; // set filter
var filterSettings = {};
filterSettings.range = {sheetId: ss.getSheetByName('Aufgaben').getSheetId(), startRowIndex: 1};
filterSettings.criteria = {};
var columnIndex = 4;
filterSettings['criteria'][columnIndex] = {'condition': filterCriteria}; // Modified
var request = {setBasicFilter: {filter: filterSettings}};
Browser.msgBox(JSON.stringify({'requests': [request]})); //only works, when this line is added!
Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId()); `
The code works, but ONLY if I add Browser.msgBoxone line above Sheets.Spreadsheets.batchUpdate(). Otherwise I get this error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
at onEdit(test:127)
Since I've already spent hours trying to solve this. Thank you.
The code works, but ONLY if I add Browser.msgBoxone line above Sheets.Spreadsheets.batchUpdate(). When the script is run by script editor, it works. But if it's run by the simple trigger and custom function, such error occurs. Custom function cannot useBrowser.msgBox. So if you run it with the simple trigger, how about modifying to the installable trigger? Ref At that time, please modify the function name in order to prevent the double running. If I misunderstood your situation, I apologize. - TanaikeonEdit(). I insertedBrowser.msgBox...as a simple way to check the parameters and all of a sudden, the code did't produce the error, that was chance. I just don't understand, how this could prevent the error? If I comment out or deleteBrowser.msgBox...I get the oauth-error. Even works withBrowser.msgBox('hello'). Very strange. - hariioom