“Cannot Call SpreadsheetApp.getUi() from context” while trying to run manually
I am trying to access the UI object in Apps Script the same way I always do, inf fact the code I am using is re-used code that I have already used before and it worked fine, for some reason I am getting an error message when I try to run my script saying that I "Cannot Call the .getUI()" method from this context, but that usually presents when using a trigger, but I am not, I am just running it from the IDE.
Does anyone know if there is an update or something that is messing with this? maybe I'm doing something wrong? If so I have pasted the code below
function addProject() {
var ui = SpreadsheetApp.getUi();
//var listDepartment = ss.getRangeByName("ref_departments").getValues().filter(String);
// var projectSheet = ss.getSheetByName('Project Overview');
var nameResponse = ui.prompt("What is the name of this project?");
var projectName = nameResponse.getResponseText();
var roleResponse = ui.prompt("How Many Resource/Roles are required for this project?");
var roleCount = parseInt(roleResponse.getResponseText());
// var validateDepartment = SpreadsheetApp.newDataValidation()
// .requireValueInList(listDepartment)
// .build();
// var color = ss.getRangeByName("refColor").getValue();
var lastRow = projectSheet.getLastRow();
var lastCol = projectSheet.getMaxColumns();
projectSheet.getRange(lastRow+1, 1)
.setValue(projectName)
.setVerticalAlignment("middle")
.setHorizontalAlignment("Center")
.setFontSize(16)
.setWrap(true)
.setFontWeight("bold")
.copyTo(projectSheet.getRange(lastRow+2, 1, roleCount-1, 1));
projectSheet.getRange(lastRow+1, 2, roleCount, 1).setDataValidation(validateDepartment);
projectSheet.getRange(lastRow+1, 1, roleCount,lastCol).setBackground(color);
var rowPos = lastRow + 1;
// projectSheet.getRange(lastRow+1, 6).setFormula('=if(D'+rowPos+'="","-",if(counta(G'+rowPos+':KV'+rowPos+')<D'+rowPos+',D'+rowPos+'-counta(G'+rowPos+':KV'+rowPos+'),"Full Allocation"))')
// .copyTo(projectSheet.getRange(lastRow+2,6,roleCount-1,1));
//
projectSheet.getRange(lastRow+roleCount+1, 1).setValue("-");
// if( color == "#efefef")
// {
// ss.getRangeByName("refColor").setValue("#ffffff")
// }
// else ss.getRangeByName("refColor").setValue("#efefef");
//
/* Project Name */ variablesSheet.getRange(variablesSheetLastRow+1,1).setValue(projectName);
/* Start Cell*/ variablesSheet.getRange(variablesSheetLastRow+1,2).setValue(projectSheet.getRange(lastRow+1, 1).getA1Notation());
/*End Cell */ variablesSheet.getRange(variablesSheetLastRow+1,3).setValue( projectSheet.getRange(lastRow+1+roleCount, 1).getA1Notation());
/* Number of Jobs */ variablesSheet.getRange(variablesSheetLastRow+1,4).setValue(roleCount);
/* Date Cell */ variablesSheet.getRange(variablesSheetLastRow+1,5).setValue(projectSheet.getRange(lastRow, 7).getA1Notation());
}
function staffHeaders(){
var ss = SpreadsheetApp.getActive();
var utilSheet = ss.getSheetByName("Staff Utilization");
var staffNames = ss.getRangeByName("ref_staff").getValues().filter(String);
utilSheet.getRange(1,1,1,utilSheet.getMaxRows()).clearContent();
for (i = 1; i< staffNames.length ; i++)
{
utilSheet.getRange(1, i+1).setValue(staffNames[i]);
}
}
javascript google-apps-script google-sheets
add a comment |
I am trying to access the UI object in Apps Script the same way I always do, inf fact the code I am using is re-used code that I have already used before and it worked fine, for some reason I am getting an error message when I try to run my script saying that I "Cannot Call the .getUI()" method from this context, but that usually presents when using a trigger, but I am not, I am just running it from the IDE.
Does anyone know if there is an update or something that is messing with this? maybe I'm doing something wrong? If so I have pasted the code below
function addProject() {
var ui = SpreadsheetApp.getUi();
//var listDepartment = ss.getRangeByName("ref_departments").getValues().filter(String);
// var projectSheet = ss.getSheetByName('Project Overview');
var nameResponse = ui.prompt("What is the name of this project?");
var projectName = nameResponse.getResponseText();
var roleResponse = ui.prompt("How Many Resource/Roles are required for this project?");
var roleCount = parseInt(roleResponse.getResponseText());
// var validateDepartment = SpreadsheetApp.newDataValidation()
// .requireValueInList(listDepartment)
// .build();
// var color = ss.getRangeByName("refColor").getValue();
var lastRow = projectSheet.getLastRow();
var lastCol = projectSheet.getMaxColumns();
projectSheet.getRange(lastRow+1, 1)
.setValue(projectName)
.setVerticalAlignment("middle")
.setHorizontalAlignment("Center")
.setFontSize(16)
.setWrap(true)
.setFontWeight("bold")
.copyTo(projectSheet.getRange(lastRow+2, 1, roleCount-1, 1));
projectSheet.getRange(lastRow+1, 2, roleCount, 1).setDataValidation(validateDepartment);
projectSheet.getRange(lastRow+1, 1, roleCount,lastCol).setBackground(color);
var rowPos = lastRow + 1;
// projectSheet.getRange(lastRow+1, 6).setFormula('=if(D'+rowPos+'="","-",if(counta(G'+rowPos+':KV'+rowPos+')<D'+rowPos+',D'+rowPos+'-counta(G'+rowPos+':KV'+rowPos+'),"Full Allocation"))')
// .copyTo(projectSheet.getRange(lastRow+2,6,roleCount-1,1));
//
projectSheet.getRange(lastRow+roleCount+1, 1).setValue("-");
// if( color == "#efefef")
// {
// ss.getRangeByName("refColor").setValue("#ffffff")
// }
// else ss.getRangeByName("refColor").setValue("#efefef");
//
/* Project Name */ variablesSheet.getRange(variablesSheetLastRow+1,1).setValue(projectName);
/* Start Cell*/ variablesSheet.getRange(variablesSheetLastRow+1,2).setValue(projectSheet.getRange(lastRow+1, 1).getA1Notation());
/*End Cell */ variablesSheet.getRange(variablesSheetLastRow+1,3).setValue( projectSheet.getRange(lastRow+1+roleCount, 1).getA1Notation());
/* Number of Jobs */ variablesSheet.getRange(variablesSheetLastRow+1,4).setValue(roleCount);
/* Date Cell */ variablesSheet.getRange(variablesSheetLastRow+1,5).setValue(projectSheet.getRange(lastRow, 7).getA1Notation());
}
function staffHeaders(){
var ss = SpreadsheetApp.getActive();
var utilSheet = ss.getSheetByName("Staff Utilization");
var staffNames = ss.getRangeByName("ref_staff").getValues().filter(String);
utilSheet.getRange(1,1,1,utilSheet.getMaxRows()).clearContent();
for (i = 1; i< staffNames.length ; i++)
{
utilSheet.getRange(1, i+1).setValue(staffNames[i]);
}
}
javascript google-apps-script google-sheets
add a comment |
I am trying to access the UI object in Apps Script the same way I always do, inf fact the code I am using is re-used code that I have already used before and it worked fine, for some reason I am getting an error message when I try to run my script saying that I "Cannot Call the .getUI()" method from this context, but that usually presents when using a trigger, but I am not, I am just running it from the IDE.
Does anyone know if there is an update or something that is messing with this? maybe I'm doing something wrong? If so I have pasted the code below
function addProject() {
var ui = SpreadsheetApp.getUi();
//var listDepartment = ss.getRangeByName("ref_departments").getValues().filter(String);
// var projectSheet = ss.getSheetByName('Project Overview');
var nameResponse = ui.prompt("What is the name of this project?");
var projectName = nameResponse.getResponseText();
var roleResponse = ui.prompt("How Many Resource/Roles are required for this project?");
var roleCount = parseInt(roleResponse.getResponseText());
// var validateDepartment = SpreadsheetApp.newDataValidation()
// .requireValueInList(listDepartment)
// .build();
// var color = ss.getRangeByName("refColor").getValue();
var lastRow = projectSheet.getLastRow();
var lastCol = projectSheet.getMaxColumns();
projectSheet.getRange(lastRow+1, 1)
.setValue(projectName)
.setVerticalAlignment("middle")
.setHorizontalAlignment("Center")
.setFontSize(16)
.setWrap(true)
.setFontWeight("bold")
.copyTo(projectSheet.getRange(lastRow+2, 1, roleCount-1, 1));
projectSheet.getRange(lastRow+1, 2, roleCount, 1).setDataValidation(validateDepartment);
projectSheet.getRange(lastRow+1, 1, roleCount,lastCol).setBackground(color);
var rowPos = lastRow + 1;
// projectSheet.getRange(lastRow+1, 6).setFormula('=if(D'+rowPos+'="","-",if(counta(G'+rowPos+':KV'+rowPos+')<D'+rowPos+',D'+rowPos+'-counta(G'+rowPos+':KV'+rowPos+'),"Full Allocation"))')
// .copyTo(projectSheet.getRange(lastRow+2,6,roleCount-1,1));
//
projectSheet.getRange(lastRow+roleCount+1, 1).setValue("-");
// if( color == "#efefef")
// {
// ss.getRangeByName("refColor").setValue("#ffffff")
// }
// else ss.getRangeByName("refColor").setValue("#efefef");
//
/* Project Name */ variablesSheet.getRange(variablesSheetLastRow+1,1).setValue(projectName);
/* Start Cell*/ variablesSheet.getRange(variablesSheetLastRow+1,2).setValue(projectSheet.getRange(lastRow+1, 1).getA1Notation());
/*End Cell */ variablesSheet.getRange(variablesSheetLastRow+1,3).setValue( projectSheet.getRange(lastRow+1+roleCount, 1).getA1Notation());
/* Number of Jobs */ variablesSheet.getRange(variablesSheetLastRow+1,4).setValue(roleCount);
/* Date Cell */ variablesSheet.getRange(variablesSheetLastRow+1,5).setValue(projectSheet.getRange(lastRow, 7).getA1Notation());
}
function staffHeaders(){
var ss = SpreadsheetApp.getActive();
var utilSheet = ss.getSheetByName("Staff Utilization");
var staffNames = ss.getRangeByName("ref_staff").getValues().filter(String);
utilSheet.getRange(1,1,1,utilSheet.getMaxRows()).clearContent();
for (i = 1; i< staffNames.length ; i++)
{
utilSheet.getRange(1, i+1).setValue(staffNames[i]);
}
}
javascript google-apps-script google-sheets
I am trying to access the UI object in Apps Script the same way I always do, inf fact the code I am using is re-used code that I have already used before and it worked fine, for some reason I am getting an error message when I try to run my script saying that I "Cannot Call the .getUI()" method from this context, but that usually presents when using a trigger, but I am not, I am just running it from the IDE.
Does anyone know if there is an update or something that is messing with this? maybe I'm doing something wrong? If so I have pasted the code below
function addProject() {
var ui = SpreadsheetApp.getUi();
//var listDepartment = ss.getRangeByName("ref_departments").getValues().filter(String);
// var projectSheet = ss.getSheetByName('Project Overview');
var nameResponse = ui.prompt("What is the name of this project?");
var projectName = nameResponse.getResponseText();
var roleResponse = ui.prompt("How Many Resource/Roles are required for this project?");
var roleCount = parseInt(roleResponse.getResponseText());
// var validateDepartment = SpreadsheetApp.newDataValidation()
// .requireValueInList(listDepartment)
// .build();
// var color = ss.getRangeByName("refColor").getValue();
var lastRow = projectSheet.getLastRow();
var lastCol = projectSheet.getMaxColumns();
projectSheet.getRange(lastRow+1, 1)
.setValue(projectName)
.setVerticalAlignment("middle")
.setHorizontalAlignment("Center")
.setFontSize(16)
.setWrap(true)
.setFontWeight("bold")
.copyTo(projectSheet.getRange(lastRow+2, 1, roleCount-1, 1));
projectSheet.getRange(lastRow+1, 2, roleCount, 1).setDataValidation(validateDepartment);
projectSheet.getRange(lastRow+1, 1, roleCount,lastCol).setBackground(color);
var rowPos = lastRow + 1;
// projectSheet.getRange(lastRow+1, 6).setFormula('=if(D'+rowPos+'="","-",if(counta(G'+rowPos+':KV'+rowPos+')<D'+rowPos+',D'+rowPos+'-counta(G'+rowPos+':KV'+rowPos+'),"Full Allocation"))')
// .copyTo(projectSheet.getRange(lastRow+2,6,roleCount-1,1));
//
projectSheet.getRange(lastRow+roleCount+1, 1).setValue("-");
// if( color == "#efefef")
// {
// ss.getRangeByName("refColor").setValue("#ffffff")
// }
// else ss.getRangeByName("refColor").setValue("#efefef");
//
/* Project Name */ variablesSheet.getRange(variablesSheetLastRow+1,1).setValue(projectName);
/* Start Cell*/ variablesSheet.getRange(variablesSheetLastRow+1,2).setValue(projectSheet.getRange(lastRow+1, 1).getA1Notation());
/*End Cell */ variablesSheet.getRange(variablesSheetLastRow+1,3).setValue( projectSheet.getRange(lastRow+1+roleCount, 1).getA1Notation());
/* Number of Jobs */ variablesSheet.getRange(variablesSheetLastRow+1,4).setValue(roleCount);
/* Date Cell */ variablesSheet.getRange(variablesSheetLastRow+1,5).setValue(projectSheet.getRange(lastRow, 7).getA1Notation());
}
function staffHeaders(){
var ss = SpreadsheetApp.getActive();
var utilSheet = ss.getSheetByName("Staff Utilization");
var staffNames = ss.getRangeByName("ref_staff").getValues().filter(String);
utilSheet.getRange(1,1,1,utilSheet.getMaxRows()).clearContent();
for (i = 1; i< staffNames.length ; i++)
{
utilSheet.getRange(1, i+1).setValue(staffNames[i]);
}
}
javascript google-apps-script google-sheets
javascript google-apps-script google-sheets
edited Nov 19 '18 at 22:27
Rubén
11.1k43568
11.1k43568
asked Nov 19 '18 at 20:52
MeruvaMeruva
64
64
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The Class UI can't be called from the Apps Script IDE but it could be called from a script run from a custom menu, dialog or clicking an image with a script attached to it.
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%2f53382469%2fcannot-call-spreadsheetapp-getui-from-context-while-trying-to-run-manually%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Class UI can't be called from the Apps Script IDE but it could be called from a script run from a custom menu, dialog or clicking an image with a script attached to it.
add a comment |
The Class UI can't be called from the Apps Script IDE but it could be called from a script run from a custom menu, dialog or clicking an image with a script attached to it.
add a comment |
The Class UI can't be called from the Apps Script IDE but it could be called from a script run from a custom menu, dialog or clicking an image with a script attached to it.
The Class UI can't be called from the Apps Script IDE but it could be called from a script run from a custom menu, dialog or clicking an image with a script attached to it.
answered Nov 19 '18 at 22:29
RubénRubén
11.1k43568
11.1k43568
add a comment |
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%2f53382469%2fcannot-call-spreadsheetapp-getui-from-context-while-trying-to-run-manually%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