I have written functions in the app script bound to a google sheet that validates sheet data and shows a pop up in the sheet when there is an error.
Now, I am calling same functions form API calls in a Node js application to return a validation response without interacting google sheet.
API calls are successful, function gets called but unable to initialize UI. I just don't want to write duplicate functions for same purpose but without accessing UI.
I get an error that says Script error message: Exception: Cannot call SpreadsheetApp.getUi() from this context.
How do I solve this issue by retaining the UI calling functionality of the app script functions and also getting work done through API?
CodePudding user response:
You can put the call in a try catch block.
try {
SpreadsheetApp.getUi();
} catch (f) {
// do nothing here
}