Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Meaning This error happens on context mismatch and is specific to container-bound scripts. The reason for the error is attempting to call a method only available in one document type (usually, ge...
Answer
#5: Post edited
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
The reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
- The reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from a script bound to a document of other type (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).
- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
#4: Post edited
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
The primary reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).- **Reproducing**
To get a container-bound script context mismatch error, declare and run this function in a script project in either a standalone script or one that is container-bound to a document other than a Google Docs one:- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
- The reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).
- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
#3: Post edited
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
- The primary reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).
A secondary case is attempting to access a service not listed as a [supported service](https://developers.google.com/apps-script/guides/sheets/functions#using_services) in a [custom function](https://developers.google.com/apps-script/guides/sheets/functions#using_services) (a function marked by a special JSDoc-style comment `@customfunction` that can be used as a formula in Google Sheets).- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a script project in either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
- The primary reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).
- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a script project in either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
#2: Post edited
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
- The primary reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).
- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a script project in either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
- **Meaning**
- This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound).
- The primary reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone).
- A secondary case is attempting to access a service not listed as a [supported service](https://developers.google.com/apps-script/guides/sheets/functions#using_services) in a [custom function](https://developers.google.com/apps-script/guides/sheets/functions#using_services) (a function marked by a special JSDoc-style comment `@customfunction` that can be used as a formula in Google Sheets).
- **Reproducing**
- To get a container-bound script context mismatch error, declare and run this function in a script project in either a standalone script or one that is container-bound to a document other than a Google Docs one:
- ```javascript
- const cannotCallFromThisContext = () => {
- try {
- DocumentApp.getUi();
- } catch(e) {
- console.log(e);
- }
- };
- ```
- **Fixing**
- There is no fix for the error _per se_ other than removing all calls for container-bound methods.
#1: Initial revision
**Meaning** This error happens on **context mismatch** and is specific to [container-bound scripts](https://developers.google.com/apps-script/guides/bound). The primary reason for the error is attempting to call a method only available *in one document type* (usually, `getUi()` as its [`Ui`](https://developers.google.com/apps-script/reference/base/ui) class is shared between services) from another (i.e., `DocumentApp.getUi()` from a spreadsheet-bound script) or from a [standalone script](https://developers.google.com/apps-script/guides/standalone). **Reproducing** To get a container-bound script context mismatch error, declare and run this function in a script project in either a standalone script or one that is container-bound to a document other than a Google Docs one: ```javascript const cannotCallFromThisContext = () => { try { DocumentApp.getUi(); } catch(e) { console.log(e); } }; ``` **Fixing** There is no fix for the error _per se_ other than removing all calls for container-bound methods.