How do I determine what caused my script to run?
Whenever I attempt to display a UI dialog (e.g. msgBox or alert) it works fine when invoked via a menu item (e.g. from Google Sheets), but it hangs my script if I try to invoke it from the Google Apps Script editor (e.g. via Run > Run function).
My guess is it's because the Google Apps Script editor can't display any UI. To resolve this, I'd like to create a wrapper function that checks how the script was run, and not present UI depending on the source.
The "Executions" screen has the notion of Type (Editor, Standalone, Trigger):
This makes me think there is a way to get this type in code somehow.
Psuedo code of what the function might look like:
function showMessage(message) {
var scriptSource = ???;
if (scriptSource === "Standalone") {
Browser.msgBox(message);
} else {
console.log(message);
}
}
How would I get the scriptSource?
The closest thing I can find is TriggerSource, but that is missing the enum values 'Editor' and 'Trigger'. Furthermore, it's a property only available on a Trigger. I don't know how to access the current trigger. From my understanding, that's only available via the event object (e.g. via triggerUid) on functions acting as triggers. This method I'm running in the apps script editor doesn't have access to an event object.
google-apps-script
add a comment |
Whenever I attempt to display a UI dialog (e.g. msgBox or alert) it works fine when invoked via a menu item (e.g. from Google Sheets), but it hangs my script if I try to invoke it from the Google Apps Script editor (e.g. via Run > Run function).
My guess is it's because the Google Apps Script editor can't display any UI. To resolve this, I'd like to create a wrapper function that checks how the script was run, and not present UI depending on the source.
The "Executions" screen has the notion of Type (Editor, Standalone, Trigger):
This makes me think there is a way to get this type in code somehow.
Psuedo code of what the function might look like:
function showMessage(message) {
var scriptSource = ???;
if (scriptSource === "Standalone") {
Browser.msgBox(message);
} else {
console.log(message);
}
}
How would I get the scriptSource?
The closest thing I can find is TriggerSource, but that is missing the enum values 'Editor' and 'Trigger'. Furthermore, it's a property only available on a Trigger. I don't know how to access the current trigger. From my understanding, that's only available via the event object (e.g. via triggerUid) on functions acting as triggers. This method I'm running in the apps script editor doesn't have access to an event object.
google-apps-script
1
If I misunderstand your situation, I'm sorry. For example, when you want to know whether UI can be used for functions in the project, how about knowing whether the project is the container-bound script type or the standalone script type? Also although the bound script of Google Form has the method ofgetUi(),Browser.msgBox()cannot be used. I think that there are several methods for confirming them.
– Tanaike
Dec 30 '18 at 7:06
@Tanaike: How do I find out "whether the project is the container-bound script type or the standalone script type"? I think that would solve my problem.
– Senseful
Dec 30 '18 at 16:07
@Tanaike: Also regarding "getUi(),Browser.msgBox()cannot be used ... there are several methods for confirming them," how do I do that? That would probably be an even better way to solve my problem. I thought it would be as simple as checking if those functions returnundefined, but, alas, that's not the case. They both return valid values, yet hang my script if invoked via the Editor.
– Senseful
Dec 30 '18 at 16:09
Based upon your answer you have a script that is contained in a Spreadsheet. If you want to display a dialog take a look at the UI Class.
– Cooper
Dec 30 '18 at 20:21
@Senseful Thank you for replying. I posted an answer including a workaround. Could you please confirm it?
– Tanaike
Dec 30 '18 at 23:24
add a comment |
Whenever I attempt to display a UI dialog (e.g. msgBox or alert) it works fine when invoked via a menu item (e.g. from Google Sheets), but it hangs my script if I try to invoke it from the Google Apps Script editor (e.g. via Run > Run function).
My guess is it's because the Google Apps Script editor can't display any UI. To resolve this, I'd like to create a wrapper function that checks how the script was run, and not present UI depending on the source.
The "Executions" screen has the notion of Type (Editor, Standalone, Trigger):
This makes me think there is a way to get this type in code somehow.
Psuedo code of what the function might look like:
function showMessage(message) {
var scriptSource = ???;
if (scriptSource === "Standalone") {
Browser.msgBox(message);
} else {
console.log(message);
}
}
How would I get the scriptSource?
The closest thing I can find is TriggerSource, but that is missing the enum values 'Editor' and 'Trigger'. Furthermore, it's a property only available on a Trigger. I don't know how to access the current trigger. From my understanding, that's only available via the event object (e.g. via triggerUid) on functions acting as triggers. This method I'm running in the apps script editor doesn't have access to an event object.
google-apps-script
Whenever I attempt to display a UI dialog (e.g. msgBox or alert) it works fine when invoked via a menu item (e.g. from Google Sheets), but it hangs my script if I try to invoke it from the Google Apps Script editor (e.g. via Run > Run function).
My guess is it's because the Google Apps Script editor can't display any UI. To resolve this, I'd like to create a wrapper function that checks how the script was run, and not present UI depending on the source.
The "Executions" screen has the notion of Type (Editor, Standalone, Trigger):
This makes me think there is a way to get this type in code somehow.
Psuedo code of what the function might look like:
function showMessage(message) {
var scriptSource = ???;
if (scriptSource === "Standalone") {
Browser.msgBox(message);
} else {
console.log(message);
}
}
How would I get the scriptSource?
The closest thing I can find is TriggerSource, but that is missing the enum values 'Editor' and 'Trigger'. Furthermore, it's a property only available on a Trigger. I don't know how to access the current trigger. From my understanding, that's only available via the event object (e.g. via triggerUid) on functions acting as triggers. This method I'm running in the apps script editor doesn't have access to an event object.
google-apps-script
google-apps-script
asked Dec 30 '18 at 4:31
SensefulSenseful
45.7k42201319
45.7k42201319
1
If I misunderstand your situation, I'm sorry. For example, when you want to know whether UI can be used for functions in the project, how about knowing whether the project is the container-bound script type or the standalone script type? Also although the bound script of Google Form has the method ofgetUi(),Browser.msgBox()cannot be used. I think that there are several methods for confirming them.
– Tanaike
Dec 30 '18 at 7:06
@Tanaike: How do I find out "whether the project is the container-bound script type or the standalone script type"? I think that would solve my problem.
– Senseful
Dec 30 '18 at 16:07
@Tanaike: Also regarding "getUi(),Browser.msgBox()cannot be used ... there are several methods for confirming them," how do I do that? That would probably be an even better way to solve my problem. I thought it would be as simple as checking if those functions returnundefined, but, alas, that's not the case. They both return valid values, yet hang my script if invoked via the Editor.
– Senseful
Dec 30 '18 at 16:09
Based upon your answer you have a script that is contained in a Spreadsheet. If you want to display a dialog take a look at the UI Class.
– Cooper
Dec 30 '18 at 20:21
@Senseful Thank you for replying. I posted an answer including a workaround. Could you please confirm it?
– Tanaike
Dec 30 '18 at 23:24
add a comment |
1
If I misunderstand your situation, I'm sorry. For example, when you want to know whether UI can be used for functions in the project, how about knowing whether the project is the container-bound script type or the standalone script type? Also although the bound script of Google Form has the method ofgetUi(),Browser.msgBox()cannot be used. I think that there are several methods for confirming them.
– Tanaike
Dec 30 '18 at 7:06
@Tanaike: How do I find out "whether the project is the container-bound script type or the standalone script type"? I think that would solve my problem.
– Senseful
Dec 30 '18 at 16:07
@Tanaike: Also regarding "getUi(),Browser.msgBox()cannot be used ... there are several methods for confirming them," how do I do that? That would probably be an even better way to solve my problem. I thought it would be as simple as checking if those functions returnundefined, but, alas, that's not the case. They both return valid values, yet hang my script if invoked via the Editor.
– Senseful
Dec 30 '18 at 16:09
Based upon your answer you have a script that is contained in a Spreadsheet. If you want to display a dialog take a look at the UI Class.
– Cooper
Dec 30 '18 at 20:21
@Senseful Thank you for replying. I posted an answer including a workaround. Could you please confirm it?
– Tanaike
Dec 30 '18 at 23:24
1
1
If I misunderstand your situation, I'm sorry. For example, when you want to know whether UI can be used for functions in the project, how about knowing whether the project is the container-bound script type or the standalone script type? Also although the bound script of Google Form has the method of
getUi(), Browser.msgBox() cannot be used. I think that there are several methods for confirming them.– Tanaike
Dec 30 '18 at 7:06
If I misunderstand your situation, I'm sorry. For example, when you want to know whether UI can be used for functions in the project, how about knowing whether the project is the container-bound script type or the standalone script type? Also although the bound script of Google Form has the method of
getUi(), Browser.msgBox() cannot be used. I think that there are several methods for confirming them.– Tanaike
Dec 30 '18 at 7:06
@Tanaike: How do I find out "whether the project is the container-bound script type or the standalone script type"? I think that would solve my problem.
– Senseful
Dec 30 '18 at 16:07
@Tanaike: How do I find out "whether the project is the container-bound script type or the standalone script type"? I think that would solve my problem.
– Senseful
Dec 30 '18 at 16:07
@Tanaike: Also regarding "
getUi(), Browser.msgBox() cannot be used ... there are several methods for confirming them," how do I do that? That would probably be an even better way to solve my problem. I thought it would be as simple as checking if those functions return undefined, but, alas, that's not the case. They both return valid values, yet hang my script if invoked via the Editor.– Senseful
Dec 30 '18 at 16:09
@Tanaike: Also regarding "
getUi(), Browser.msgBox() cannot be used ... there are several methods for confirming them," how do I do that? That would probably be an even better way to solve my problem. I thought it would be as simple as checking if those functions return undefined, but, alas, that's not the case. They both return valid values, yet hang my script if invoked via the Editor.– Senseful
Dec 30 '18 at 16:09
Based upon your answer you have a script that is contained in a Spreadsheet. If you want to display a dialog take a look at the UI Class.
– Cooper
Dec 30 '18 at 20:21
Based upon your answer you have a script that is contained in a Spreadsheet. If you want to display a dialog take a look at the UI Class.
– Cooper
Dec 30 '18 at 20:21
@Senseful Thank you for replying. I posted an answer including a workaround. Could you please confirm it?
– Tanaike
Dec 30 '18 at 23:24
@Senseful Thank you for replying. I posted an answer including a workaround. Could you please confirm it?
– Tanaike
Dec 30 '18 at 23:24
add a comment |
3 Answers
3
active
oldest
votes
Not the best solution, but my current workaround is to create 3 versions of each function, and append how it was invoked to the name.
For example, if there was a "Hello World" function:
function onOpen() {
var menu = [
{name: 'Hello World', functionName: 'helloWorldViaMenu_'},
];
SpreadsheetApp.getActive().addMenu('Custom', menu);
}
function helloWorldViaMenu_() {
helloWorld_(false);
}
function helloWorldViaEditor() {
helloWorld_(true);
}
function helloWorld_(invokedFromEditor) {
if (invokedFromEditor) {
Logger.log("Hello world");
} else {
Browser.msgBox("Hello world");
}
}
helloWorldViaEditor is the only that doesn't have a _ at the end so it can be selected via the "Select function" Editor UI dropdown.
add a comment |
- You want to know whether the current project is the container-bound script type or the standalone script type.
- You want to use
Browser.msgBox().
I could understand about your question as above. In order to achieve it, as a workaround,I would like to propose to use Apps Script API. The flow of sample script is as follows. I think that there are several workarounds for your situation. So please think of this as one of them.
- Retrieve the parent ID of the project using the method of projects.get in Apps Script API. The parent ID means that the file ID of Google Docs.
- When the parent ID is returned, it is found that the project is the container-bound script type.
- When the parent ID is NOT returned, it is found that the project is the standalone script type.
- When the mimeType of parent ID is Google Form,
Browser.msgBox()cannot be used. So the if statement is used for this.
Sample script:
This is a sample script. In this sample script, the script ID of current project is used. Of course, you can also manually give the script ID.
var id = ScriptApp.getScriptId(); // Retrieve scriptId of current project.
var url = "https://script.googleapis.com/v1/projects/" + id + "?fields=parentId";
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}});
res = JSON.parse(res.getContentText());
if ("parentId" in res) {
Logger.log("Container-bound script type.")
var mimeType = DriveApp.getFileById(res.parentId).getMimeType();
if (mimeType === MimeType.GOOGLE_FORMS) {
Logger.log("Browser.msgBox() cannot be used at Google Form.");
} else {
Browser.msgBox("Hello world");
}
} else {
Logger.log("Standalone script type.")
Logger.log("Hello world");
}
Note:
When you use this script, please do the following flow.
- Enable Apps Script API at API console.
- At least, add the following scopes to the manifests.
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/script.projects.readonly
- If in your script, other scopes are required to be added, please add them. And if you want to use the automatically installer of scopes with the script editor, you can achieve it using a library. You can see the detail information at here.
References:
- Apps Script API
- Manifests
- projects.get
- Taking Advantage of Manifests by GAS Library
If I misunderstand your question, I'm sorry.
Edit:
- You want to confirm whether the function is called from the script editor or the custom menu.
If my understanding is correct, how about this sample script? This is a sample script. The process list can be retrieved by giving the script ID and function name. In this sample script, using "ProcessType" of processes.listScriptProcesses in Apps Script API, it confirms whether the function is called from the script editor or the custom menu.
Sample script:
This is a sample script. The process list can be retrieved by giving the script ID and function name.
When you use this script, please enable Apps Script API at API console, and add a scope of https://www.googleapis.com/auth/script.processes to the manifests.
The how to use this script is as follows.
- Run
addCustomMenu(). - Run
sampleFunctionat the custom menu.
- By this,
Call from custom menuis shown in log.
- By this,
- Run
sampleFunctionat the script editor.
- By this,
Call from script editoris shown in log.
- By this,
Script:
function addCustomMenu() {
SpreadsheetApp.getUi().createMenu('sampleCustomMenu').addItem('sample', 'sampleFunction').addToUi();
}
function sampleFunction() {
var scriptId = ScriptApp.getScriptId();
var functionName = "sampleFunction";
var url = "https://script.googleapis.com/v1/processes:listScriptProcesses?scriptId=" + scriptId + "&scriptProcessFilter.functionName=" + functionName;
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions: true});
res = JSON.parse(res);
if (!("processType" in res.processes[0])) {
Logger.log("Call from custom menu")
} else if (res.processes[0].processType == "EDITOR") {
Logger.log("Call from script editor")
}
}
References:
- Apps Script API
- Manifests
- processes.listScriptProcesses
- ProcessType
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just addDriveApp.getRootFolder()to the code and it'll ask for the correct permissions).
– Senseful
Jan 2 at 8:08
1
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The wordStandaloneis used by the dashboard UI, when the function is called frommenu, even if the script iscontainer-bound. The choice of the term by Google is confusing because the script isn't really standalone.
– TheMaster
Jan 2 at 11:37
1
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
1
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
|
show 3 more comments
Making Dialogs
You can run them from the menu or the script editor. They work the same.
function makeAmenu(){
SpreadsheetApp.getUi().createMenu('A Menu')
.addItem('Run my Dialogs', 'showMyDialogs')
.addToUi();
}
function showMyDialogs(){
var ui=SpreadsheetApp.getUi();
ui.alert('This is an alert');
ui.prompt('This is a prompt');
var html=HtmlService.createHtmlOutput('<p>This is a modeless dialog</p><input type="button" value="Close" onClick="google.script.host.close();" />');
ui.showModelessDialog(html, 'Dialog');
}
If you run a script from here:

The you have to go here to see it:

Unfortunately,ui.alertcauses the same problem asBrowser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.
– Senseful
Dec 30 '18 at 22:07
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975299%2fhow-do-i-determine-what-caused-my-script-to-run%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not the best solution, but my current workaround is to create 3 versions of each function, and append how it was invoked to the name.
For example, if there was a "Hello World" function:
function onOpen() {
var menu = [
{name: 'Hello World', functionName: 'helloWorldViaMenu_'},
];
SpreadsheetApp.getActive().addMenu('Custom', menu);
}
function helloWorldViaMenu_() {
helloWorld_(false);
}
function helloWorldViaEditor() {
helloWorld_(true);
}
function helloWorld_(invokedFromEditor) {
if (invokedFromEditor) {
Logger.log("Hello world");
} else {
Browser.msgBox("Hello world");
}
}
helloWorldViaEditor is the only that doesn't have a _ at the end so it can be selected via the "Select function" Editor UI dropdown.
add a comment |
Not the best solution, but my current workaround is to create 3 versions of each function, and append how it was invoked to the name.
For example, if there was a "Hello World" function:
function onOpen() {
var menu = [
{name: 'Hello World', functionName: 'helloWorldViaMenu_'},
];
SpreadsheetApp.getActive().addMenu('Custom', menu);
}
function helloWorldViaMenu_() {
helloWorld_(false);
}
function helloWorldViaEditor() {
helloWorld_(true);
}
function helloWorld_(invokedFromEditor) {
if (invokedFromEditor) {
Logger.log("Hello world");
} else {
Browser.msgBox("Hello world");
}
}
helloWorldViaEditor is the only that doesn't have a _ at the end so it can be selected via the "Select function" Editor UI dropdown.
add a comment |
Not the best solution, but my current workaround is to create 3 versions of each function, and append how it was invoked to the name.
For example, if there was a "Hello World" function:
function onOpen() {
var menu = [
{name: 'Hello World', functionName: 'helloWorldViaMenu_'},
];
SpreadsheetApp.getActive().addMenu('Custom', menu);
}
function helloWorldViaMenu_() {
helloWorld_(false);
}
function helloWorldViaEditor() {
helloWorld_(true);
}
function helloWorld_(invokedFromEditor) {
if (invokedFromEditor) {
Logger.log("Hello world");
} else {
Browser.msgBox("Hello world");
}
}
helloWorldViaEditor is the only that doesn't have a _ at the end so it can be selected via the "Select function" Editor UI dropdown.
Not the best solution, but my current workaround is to create 3 versions of each function, and append how it was invoked to the name.
For example, if there was a "Hello World" function:
function onOpen() {
var menu = [
{name: 'Hello World', functionName: 'helloWorldViaMenu_'},
];
SpreadsheetApp.getActive().addMenu('Custom', menu);
}
function helloWorldViaMenu_() {
helloWorld_(false);
}
function helloWorldViaEditor() {
helloWorld_(true);
}
function helloWorld_(invokedFromEditor) {
if (invokedFromEditor) {
Logger.log("Hello world");
} else {
Browser.msgBox("Hello world");
}
}
helloWorldViaEditor is the only that doesn't have a _ at the end so it can be selected via the "Select function" Editor UI dropdown.
answered Dec 30 '18 at 20:00
SensefulSenseful
45.7k42201319
45.7k42201319
add a comment |
add a comment |
- You want to know whether the current project is the container-bound script type or the standalone script type.
- You want to use
Browser.msgBox().
I could understand about your question as above. In order to achieve it, as a workaround,I would like to propose to use Apps Script API. The flow of sample script is as follows. I think that there are several workarounds for your situation. So please think of this as one of them.
- Retrieve the parent ID of the project using the method of projects.get in Apps Script API. The parent ID means that the file ID of Google Docs.
- When the parent ID is returned, it is found that the project is the container-bound script type.
- When the parent ID is NOT returned, it is found that the project is the standalone script type.
- When the mimeType of parent ID is Google Form,
Browser.msgBox()cannot be used. So the if statement is used for this.
Sample script:
This is a sample script. In this sample script, the script ID of current project is used. Of course, you can also manually give the script ID.
var id = ScriptApp.getScriptId(); // Retrieve scriptId of current project.
var url = "https://script.googleapis.com/v1/projects/" + id + "?fields=parentId";
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}});
res = JSON.parse(res.getContentText());
if ("parentId" in res) {
Logger.log("Container-bound script type.")
var mimeType = DriveApp.getFileById(res.parentId).getMimeType();
if (mimeType === MimeType.GOOGLE_FORMS) {
Logger.log("Browser.msgBox() cannot be used at Google Form.");
} else {
Browser.msgBox("Hello world");
}
} else {
Logger.log("Standalone script type.")
Logger.log("Hello world");
}
Note:
When you use this script, please do the following flow.
- Enable Apps Script API at API console.
- At least, add the following scopes to the manifests.
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/script.projects.readonly
- If in your script, other scopes are required to be added, please add them. And if you want to use the automatically installer of scopes with the script editor, you can achieve it using a library. You can see the detail information at here.
References:
- Apps Script API
- Manifests
- projects.get
- Taking Advantage of Manifests by GAS Library
If I misunderstand your question, I'm sorry.
Edit:
- You want to confirm whether the function is called from the script editor or the custom menu.
If my understanding is correct, how about this sample script? This is a sample script. The process list can be retrieved by giving the script ID and function name. In this sample script, using "ProcessType" of processes.listScriptProcesses in Apps Script API, it confirms whether the function is called from the script editor or the custom menu.
Sample script:
This is a sample script. The process list can be retrieved by giving the script ID and function name.
When you use this script, please enable Apps Script API at API console, and add a scope of https://www.googleapis.com/auth/script.processes to the manifests.
The how to use this script is as follows.
- Run
addCustomMenu(). - Run
sampleFunctionat the custom menu.
- By this,
Call from custom menuis shown in log.
- By this,
- Run
sampleFunctionat the script editor.
- By this,
Call from script editoris shown in log.
- By this,
Script:
function addCustomMenu() {
SpreadsheetApp.getUi().createMenu('sampleCustomMenu').addItem('sample', 'sampleFunction').addToUi();
}
function sampleFunction() {
var scriptId = ScriptApp.getScriptId();
var functionName = "sampleFunction";
var url = "https://script.googleapis.com/v1/processes:listScriptProcesses?scriptId=" + scriptId + "&scriptProcessFilter.functionName=" + functionName;
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions: true});
res = JSON.parse(res);
if (!("processType" in res.processes[0])) {
Logger.log("Call from custom menu")
} else if (res.processes[0].processType == "EDITOR") {
Logger.log("Call from script editor")
}
}
References:
- Apps Script API
- Manifests
- processes.listScriptProcesses
- ProcessType
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just addDriveApp.getRootFolder()to the code and it'll ask for the correct permissions).
– Senseful
Jan 2 at 8:08
1
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The wordStandaloneis used by the dashboard UI, when the function is called frommenu, even if the script iscontainer-bound. The choice of the term by Google is confusing because the script isn't really standalone.
– TheMaster
Jan 2 at 11:37
1
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
1
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
|
show 3 more comments
- You want to know whether the current project is the container-bound script type or the standalone script type.
- You want to use
Browser.msgBox().
I could understand about your question as above. In order to achieve it, as a workaround,I would like to propose to use Apps Script API. The flow of sample script is as follows. I think that there are several workarounds for your situation. So please think of this as one of them.
- Retrieve the parent ID of the project using the method of projects.get in Apps Script API. The parent ID means that the file ID of Google Docs.
- When the parent ID is returned, it is found that the project is the container-bound script type.
- When the parent ID is NOT returned, it is found that the project is the standalone script type.
- When the mimeType of parent ID is Google Form,
Browser.msgBox()cannot be used. So the if statement is used for this.
Sample script:
This is a sample script. In this sample script, the script ID of current project is used. Of course, you can also manually give the script ID.
var id = ScriptApp.getScriptId(); // Retrieve scriptId of current project.
var url = "https://script.googleapis.com/v1/projects/" + id + "?fields=parentId";
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}});
res = JSON.parse(res.getContentText());
if ("parentId" in res) {
Logger.log("Container-bound script type.")
var mimeType = DriveApp.getFileById(res.parentId).getMimeType();
if (mimeType === MimeType.GOOGLE_FORMS) {
Logger.log("Browser.msgBox() cannot be used at Google Form.");
} else {
Browser.msgBox("Hello world");
}
} else {
Logger.log("Standalone script type.")
Logger.log("Hello world");
}
Note:
When you use this script, please do the following flow.
- Enable Apps Script API at API console.
- At least, add the following scopes to the manifests.
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/script.projects.readonly
- If in your script, other scopes are required to be added, please add them. And if you want to use the automatically installer of scopes with the script editor, you can achieve it using a library. You can see the detail information at here.
References:
- Apps Script API
- Manifests
- projects.get
- Taking Advantage of Manifests by GAS Library
If I misunderstand your question, I'm sorry.
Edit:
- You want to confirm whether the function is called from the script editor or the custom menu.
If my understanding is correct, how about this sample script? This is a sample script. The process list can be retrieved by giving the script ID and function name. In this sample script, using "ProcessType" of processes.listScriptProcesses in Apps Script API, it confirms whether the function is called from the script editor or the custom menu.
Sample script:
This is a sample script. The process list can be retrieved by giving the script ID and function name.
When you use this script, please enable Apps Script API at API console, and add a scope of https://www.googleapis.com/auth/script.processes to the manifests.
The how to use this script is as follows.
- Run
addCustomMenu(). - Run
sampleFunctionat the custom menu.
- By this,
Call from custom menuis shown in log.
- By this,
- Run
sampleFunctionat the script editor.
- By this,
Call from script editoris shown in log.
- By this,
Script:
function addCustomMenu() {
SpreadsheetApp.getUi().createMenu('sampleCustomMenu').addItem('sample', 'sampleFunction').addToUi();
}
function sampleFunction() {
var scriptId = ScriptApp.getScriptId();
var functionName = "sampleFunction";
var url = "https://script.googleapis.com/v1/processes:listScriptProcesses?scriptId=" + scriptId + "&scriptProcessFilter.functionName=" + functionName;
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions: true});
res = JSON.parse(res);
if (!("processType" in res.processes[0])) {
Logger.log("Call from custom menu")
} else if (res.processes[0].processType == "EDITOR") {
Logger.log("Call from script editor")
}
}
References:
- Apps Script API
- Manifests
- processes.listScriptProcesses
- ProcessType
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just addDriveApp.getRootFolder()to the code and it'll ask for the correct permissions).
– Senseful
Jan 2 at 8:08
1
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The wordStandaloneis used by the dashboard UI, when the function is called frommenu, even if the script iscontainer-bound. The choice of the term by Google is confusing because the script isn't really standalone.
– TheMaster
Jan 2 at 11:37
1
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
1
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
|
show 3 more comments
- You want to know whether the current project is the container-bound script type or the standalone script type.
- You want to use
Browser.msgBox().
I could understand about your question as above. In order to achieve it, as a workaround,I would like to propose to use Apps Script API. The flow of sample script is as follows. I think that there are several workarounds for your situation. So please think of this as one of them.
- Retrieve the parent ID of the project using the method of projects.get in Apps Script API. The parent ID means that the file ID of Google Docs.
- When the parent ID is returned, it is found that the project is the container-bound script type.
- When the parent ID is NOT returned, it is found that the project is the standalone script type.
- When the mimeType of parent ID is Google Form,
Browser.msgBox()cannot be used. So the if statement is used for this.
Sample script:
This is a sample script. In this sample script, the script ID of current project is used. Of course, you can also manually give the script ID.
var id = ScriptApp.getScriptId(); // Retrieve scriptId of current project.
var url = "https://script.googleapis.com/v1/projects/" + id + "?fields=parentId";
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}});
res = JSON.parse(res.getContentText());
if ("parentId" in res) {
Logger.log("Container-bound script type.")
var mimeType = DriveApp.getFileById(res.parentId).getMimeType();
if (mimeType === MimeType.GOOGLE_FORMS) {
Logger.log("Browser.msgBox() cannot be used at Google Form.");
} else {
Browser.msgBox("Hello world");
}
} else {
Logger.log("Standalone script type.")
Logger.log("Hello world");
}
Note:
When you use this script, please do the following flow.
- Enable Apps Script API at API console.
- At least, add the following scopes to the manifests.
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/script.projects.readonly
- If in your script, other scopes are required to be added, please add them. And if you want to use the automatically installer of scopes with the script editor, you can achieve it using a library. You can see the detail information at here.
References:
- Apps Script API
- Manifests
- projects.get
- Taking Advantage of Manifests by GAS Library
If I misunderstand your question, I'm sorry.
Edit:
- You want to confirm whether the function is called from the script editor or the custom menu.
If my understanding is correct, how about this sample script? This is a sample script. The process list can be retrieved by giving the script ID and function name. In this sample script, using "ProcessType" of processes.listScriptProcesses in Apps Script API, it confirms whether the function is called from the script editor or the custom menu.
Sample script:
This is a sample script. The process list can be retrieved by giving the script ID and function name.
When you use this script, please enable Apps Script API at API console, and add a scope of https://www.googleapis.com/auth/script.processes to the manifests.
The how to use this script is as follows.
- Run
addCustomMenu(). - Run
sampleFunctionat the custom menu.
- By this,
Call from custom menuis shown in log.
- By this,
- Run
sampleFunctionat the script editor.
- By this,
Call from script editoris shown in log.
- By this,
Script:
function addCustomMenu() {
SpreadsheetApp.getUi().createMenu('sampleCustomMenu').addItem('sample', 'sampleFunction').addToUi();
}
function sampleFunction() {
var scriptId = ScriptApp.getScriptId();
var functionName = "sampleFunction";
var url = "https://script.googleapis.com/v1/processes:listScriptProcesses?scriptId=" + scriptId + "&scriptProcessFilter.functionName=" + functionName;
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions: true});
res = JSON.parse(res);
if (!("processType" in res.processes[0])) {
Logger.log("Call from custom menu")
} else if (res.processes[0].processType == "EDITOR") {
Logger.log("Call from script editor")
}
}
References:
- Apps Script API
- Manifests
- processes.listScriptProcesses
- ProcessType
- You want to know whether the current project is the container-bound script type or the standalone script type.
- You want to use
Browser.msgBox().
I could understand about your question as above. In order to achieve it, as a workaround,I would like to propose to use Apps Script API. The flow of sample script is as follows. I think that there are several workarounds for your situation. So please think of this as one of them.
- Retrieve the parent ID of the project using the method of projects.get in Apps Script API. The parent ID means that the file ID of Google Docs.
- When the parent ID is returned, it is found that the project is the container-bound script type.
- When the parent ID is NOT returned, it is found that the project is the standalone script type.
- When the mimeType of parent ID is Google Form,
Browser.msgBox()cannot be used. So the if statement is used for this.
Sample script:
This is a sample script. In this sample script, the script ID of current project is used. Of course, you can also manually give the script ID.
var id = ScriptApp.getScriptId(); // Retrieve scriptId of current project.
var url = "https://script.googleapis.com/v1/projects/" + id + "?fields=parentId";
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}});
res = JSON.parse(res.getContentText());
if ("parentId" in res) {
Logger.log("Container-bound script type.")
var mimeType = DriveApp.getFileById(res.parentId).getMimeType();
if (mimeType === MimeType.GOOGLE_FORMS) {
Logger.log("Browser.msgBox() cannot be used at Google Form.");
} else {
Browser.msgBox("Hello world");
}
} else {
Logger.log("Standalone script type.")
Logger.log("Hello world");
}
Note:
When you use this script, please do the following flow.
- Enable Apps Script API at API console.
- At least, add the following scopes to the manifests.
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/script.external_requesthttps://www.googleapis.com/auth/script.projects.readonly
- If in your script, other scopes are required to be added, please add them. And if you want to use the automatically installer of scopes with the script editor, you can achieve it using a library. You can see the detail information at here.
References:
- Apps Script API
- Manifests
- projects.get
- Taking Advantage of Manifests by GAS Library
If I misunderstand your question, I'm sorry.
Edit:
- You want to confirm whether the function is called from the script editor or the custom menu.
If my understanding is correct, how about this sample script? This is a sample script. The process list can be retrieved by giving the script ID and function name. In this sample script, using "ProcessType" of processes.listScriptProcesses in Apps Script API, it confirms whether the function is called from the script editor or the custom menu.
Sample script:
This is a sample script. The process list can be retrieved by giving the script ID and function name.
When you use this script, please enable Apps Script API at API console, and add a scope of https://www.googleapis.com/auth/script.processes to the manifests.
The how to use this script is as follows.
- Run
addCustomMenu(). - Run
sampleFunctionat the custom menu.
- By this,
Call from custom menuis shown in log.
- By this,
- Run
sampleFunctionat the script editor.
- By this,
Call from script editoris shown in log.
- By this,
Script:
function addCustomMenu() {
SpreadsheetApp.getUi().createMenu('sampleCustomMenu').addItem('sample', 'sampleFunction').addToUi();
}
function sampleFunction() {
var scriptId = ScriptApp.getScriptId();
var functionName = "sampleFunction";
var url = "https://script.googleapis.com/v1/processes:listScriptProcesses?scriptId=" + scriptId + "&scriptProcessFilter.functionName=" + functionName;
var res = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions: true});
res = JSON.parse(res);
if (!("processType" in res.processes[0])) {
Logger.log("Call from custom menu")
} else if (res.processes[0].processType == "EDITOR") {
Logger.log("Call from script editor")
}
}
References:
- Apps Script API
- Manifests
- processes.listScriptProcesses
- ProcessType
edited Jan 3 at 2:29
answered Dec 30 '18 at 5:34
TanaikeTanaike
21.1k21123
21.1k21123
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just addDriveApp.getRootFolder()to the code and it'll ask for the correct permissions).
– Senseful
Jan 2 at 8:08
1
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The wordStandaloneis used by the dashboard UI, when the function is called frommenu, even if the script iscontainer-bound. The choice of the term by Google is confusing because the script isn't really standalone.
– TheMaster
Jan 2 at 11:37
1
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
1
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
|
show 3 more comments
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just addDriveApp.getRootFolder()to the code and it'll ask for the correct permissions).
– Senseful
Jan 2 at 8:08
1
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The wordStandaloneis used by the dashboard UI, when the function is called frommenu, even if the script iscontainer-bound. The choice of the term by Google is confusing because the script isn't really standalone.
– TheMaster
Jan 2 at 11:37
1
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
1
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
@Senseful Did my answer show you the result what you want? Would you please tell me about it? That is also useful for me to study. If this works, other people who have the same issue with you can also base your question as a question which can be solved. If you have issues for my answer yet, feel free to tell me. I would like to study to solve your issues. If I misunderstand about your question, I apologize it.
– Tanaike
Jan 1 at 2:47
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just add
DriveApp.getRootFolder() to the code and it'll ask for the correct permissions).– Senseful
Jan 2 at 8:08
I haven't tried it yet. However, regarding adding app scopes, I believe there is also a shortcut method mentioned here (e.g. you can just add
DriveApp.getRootFolder() to the code and it'll ask for the correct permissions).– Senseful
Jan 2 at 8:08
1
1
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The word
Standalone is used by the dashboard UI, when the function is called from menu, even if the script is container-bound. The choice of the term by Google is confusing because the script isn't really standalone.– TheMaster
Jan 2 at 11:37
Tanaike Although the information here is useful(and I upvoted), I think @Senseful wants to know whether we can differentiate calling from a 'menu' vs calling from the 'editor'. The word
Standalone is used by the dashboard UI, when the function is called from menu, even if the script is container-bound. The choice of the term by Google is confusing because the script isn't really standalone.– TheMaster
Jan 2 at 11:37
1
1
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
@TheMaster Thank you for your comment. I had thought that OP wants to know whether the current project is the container-bound script type or the standalone script type. About whether the script is run from the script editor or the custom menu, I would like to think of it.
– Tanaike
Jan 3 at 0:52
1
1
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
@TheMaster I added a sample script for confirming whether the function is called from the script editor or the custom menu.
– Tanaike
Jan 3 at 2:29
|
show 3 more comments
Making Dialogs
You can run them from the menu or the script editor. They work the same.
function makeAmenu(){
SpreadsheetApp.getUi().createMenu('A Menu')
.addItem('Run my Dialogs', 'showMyDialogs')
.addToUi();
}
function showMyDialogs(){
var ui=SpreadsheetApp.getUi();
ui.alert('This is an alert');
ui.prompt('This is a prompt');
var html=HtmlService.createHtmlOutput('<p>This is a modeless dialog</p><input type="button" value="Close" onClick="google.script.host.close();" />');
ui.showModelessDialog(html, 'Dialog');
}
If you run a script from here:

The you have to go here to see it:

Unfortunately,ui.alertcauses the same problem asBrowser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.
– Senseful
Dec 30 '18 at 22:07
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
add a comment |
Making Dialogs
You can run them from the menu or the script editor. They work the same.
function makeAmenu(){
SpreadsheetApp.getUi().createMenu('A Menu')
.addItem('Run my Dialogs', 'showMyDialogs')
.addToUi();
}
function showMyDialogs(){
var ui=SpreadsheetApp.getUi();
ui.alert('This is an alert');
ui.prompt('This is a prompt');
var html=HtmlService.createHtmlOutput('<p>This is a modeless dialog</p><input type="button" value="Close" onClick="google.script.host.close();" />');
ui.showModelessDialog(html, 'Dialog');
}
If you run a script from here:

The you have to go here to see it:

Unfortunately,ui.alertcauses the same problem asBrowser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.
– Senseful
Dec 30 '18 at 22:07
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
add a comment |
Making Dialogs
You can run them from the menu or the script editor. They work the same.
function makeAmenu(){
SpreadsheetApp.getUi().createMenu('A Menu')
.addItem('Run my Dialogs', 'showMyDialogs')
.addToUi();
}
function showMyDialogs(){
var ui=SpreadsheetApp.getUi();
ui.alert('This is an alert');
ui.prompt('This is a prompt');
var html=HtmlService.createHtmlOutput('<p>This is a modeless dialog</p><input type="button" value="Close" onClick="google.script.host.close();" />');
ui.showModelessDialog(html, 'Dialog');
}
If you run a script from here:

The you have to go here to see it:

Making Dialogs
You can run them from the menu or the script editor. They work the same.
function makeAmenu(){
SpreadsheetApp.getUi().createMenu('A Menu')
.addItem('Run my Dialogs', 'showMyDialogs')
.addToUi();
}
function showMyDialogs(){
var ui=SpreadsheetApp.getUi();
ui.alert('This is an alert');
ui.prompt('This is a prompt');
var html=HtmlService.createHtmlOutput('<p>This is a modeless dialog</p><input type="button" value="Close" onClick="google.script.host.close();" />');
ui.showModelessDialog(html, 'Dialog');
}
If you run a script from here:

The you have to go here to see it:

edited Dec 30 '18 at 22:57
answered Dec 30 '18 at 20:42
CooperCooper
6,8012726
6,8012726
Unfortunately,ui.alertcauses the same problem asBrowser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.
– Senseful
Dec 30 '18 at 22:07
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
add a comment |
Unfortunately,ui.alertcauses the same problem asBrowser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.
– Senseful
Dec 30 '18 at 22:07
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
Unfortunately,
ui.alert causes the same problem as Browser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.– Senseful
Dec 30 '18 at 22:07
Unfortunately,
ui.alert causes the same problem as Browser.msgBox. The script hangs when running via the Editor. It runs for 300 seconds until it's force killed.– Senseful
Dec 30 '18 at 22:07
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
The dialogue does not show up over the script editor the dialogue shows up over the spreadsheet when you run a dialogue from the script editor you have to go to the spreadsheet to see it.
– Cooper
Dec 30 '18 at 22:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53975299%2fhow-do-i-determine-what-caused-my-script-to-run%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown


1
If I misunderstand your situation, I'm sorry. For example, when you want to know whether UI can be used for functions in the project, how about knowing whether the project is the container-bound script type or the standalone script type? Also although the bound script of Google Form has the method of
getUi(),Browser.msgBox()cannot be used. I think that there are several methods for confirming them.– Tanaike
Dec 30 '18 at 7:06
@Tanaike: How do I find out "whether the project is the container-bound script type or the standalone script type"? I think that would solve my problem.
– Senseful
Dec 30 '18 at 16:07
@Tanaike: Also regarding "
getUi(),Browser.msgBox()cannot be used ... there are several methods for confirming them," how do I do that? That would probably be an even better way to solve my problem. I thought it would be as simple as checking if those functions returnundefined, but, alas, that's not the case. They both return valid values, yet hang my script if invoked via the Editor.– Senseful
Dec 30 '18 at 16:09
Based upon your answer you have a script that is contained in a Spreadsheet. If you want to display a dialog take a look at the UI Class.
– Cooper
Dec 30 '18 at 20:21
@Senseful Thank you for replying. I posted an answer including a workaround. Could you please confirm it?
– Tanaike
Dec 30 '18 at 23:24