retrieving EntryID for Checkbox item in Google Sheets Form not working - google-apps-script

I used the code from #contributorpw on this post get Entry ID which is used to pre-populate fields (Items) in a Google Form URL and added the extended list of form types from #SourceFli (in same post).
I get the error message: "Exception: The parameters (String) don't match the method signature for FormApp.CheckboxItem.createResponse". That checkbox has only 1 option: "yes".
The rest of all my form items are only TEXT items and work fine.
function getPreFillEntriesMap(){
var ssOrder = SpreadsheetApp.openById(ORDER_SPREADSHEET_ID);
var orderFormUrl = ssOrder.getFormUrl();
var orderForm = FormApp.openByUrl(orderFormUrl);
var form = orderForm;
// var form = FormApp.openById(id);
var items = form.getItems();
var newFormResponse = form.createResponse();
var itms = [];
for(var i = 0; i < items.length; i++){
var response = getDefaultItemResponse_(items[i]);
if(response){
newFormResponse.withItemResponse(response);
itms.push({
id: items[i].getId(),
entry: null,
title: items[i].getTitle(),
type: "" + items[i].getType()
});
}
}
var ens = newFormResponse.toPrefilledUrl().split("&entry.").map(function(s){
return s.split("=")[0];
});
ens.shift();
return Logger.log(itms.map(function(r, i){
r.entry = this[i];
return r;
}, ens));
}
function getDefaultItemResponse_(item){
switch(item.getType()){
case FormApp.ItemType.TEXT:
return item.asTextItem().createResponse("1");
break;
case FormApp.ItemType.MULTIPLE_CHOICE:
return item.asMultipleChoiceItem()
.createResponse(item.asMultipleChoiceItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.CHECKBOX:
return item.asCheckboxItem()
.createResponse(item.asCheckboxItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.DATETIME:
return item.asDateTimeItem()
.createResponse(new Date());
break;
case FormApp.ItemType.DATE:
return item.asDateItem()
.createResponse(new Date());
break;
case FormApp.ItemType.LIST:
return item.asListItem()
.createResponse(item.asListItem().getChoices()[0].getValue());
break;
case FormApp.ItemType.PARAGRAPH_TEXT:
return item.asParagraphTextItem()
.createResponse(item.asParagraphTextItem().createResponse("some paragraph"));
break;
case FormApp.ItemType.CHECKBOX_GRID:
return item.asCheckboxGridItem()
.createResponse(item.asCheckboxGridItem().createResponse([item.asGridItem().getColumns[0], item.asGridItem().getRows[0]]));
break;
case FormApp.ItemType.DURATION:
return item.asDurationItem()
.createResponse(item.asDurationItem().createResponse(2, 20, 20));
break;
case FormApp.ItemType.GRID:
return item.asGridItem()
.createResponse(item.asGridItem().createResponse([item.asGridItem().getColumns[0], item.asGridItem().getRows[0]]));
break;
case FormApp.ItemType.SCALE:
return item.asScaleItem()
.createResponse(item.asScaleItem().createResponse(1));
break;
case FormApp.ItemType.TIME:
return item.asTimeItem()
.createResponse(item.asTimeItem().createResponse(1, 1));
break;
default:
return undefined;
}
}

response of createResponse(responses) of Class CheckboxItem is String[]. In your script, the string is used. I thought that this might be the reason of your issue. So how about the following modification?
From:
return item.asCheckboxItem()
.createResponse(item.asCheckboxItem().getChoices()[0].getValue());
To:
return item.asCheckboxItem()
.createResponse([item.asCheckboxItem().getChoices()[0].getValue()]);
Reference:
createResponse(responses)

Related

Apps Script turn value between functions

Hello everyone)) I have problem with moving value inside th function, please help me
First I have field "allValid" - has taken boolean value "true".
Next I did 3 checking breakpoints in script where this field must change boolean value on "false".
But whatever i do allValid always has "true". I cant understand what am I doing wrong.
function ButtonClickAction(){
let allValid = true;
var UserInfo = {};
UserInfo.zLOGIN = document.getElementById("LOGIN").value;
UserInfo.zSSCC = document.getElementById("SSCC").value;
UserInfo.zPLACE = document.getElementById("PLACE").value;
var toValidate = {
LOGIN: "LOGIN REQUIRED",
SSCC: "SSCC REQUIRED",
PLACE: "PLACE REQUIRED"
}
var idKeys = Object.keys(toValidate);
//first checking
idKeys.forEach(function(id){
isValid = checkIfValid(id,toValidate[id]);
allValid = isValid;
});
//second checking
google.script.run.withSuccessHandler(onLOGIN).searchLogins(UserInfo);
function onLOGIN(findLogin) {
if (!findLogin) {
alert("LOGIN NOT EXIST");
allValid = false;
}
}
//thirdchecking
console.log(allValid);
google.script.run.withSuccessHandler(onSSCC).searchSSCC(UserInfo);
function onSSCC(findSSCC) {
if (!findSSCC) {
alert("SSCC NOT EXIST");
allValid = false;
}
}
//finish result
if (!allValid){
alert("YOU HAVE NOTHING");
}
else {
addRecord(idElem);
}
}
function checkIfValid(elId, message){
var isValid = document.getElementById(elId).checkValidity();
if(!isValid){
alert(message);
return false;
}
return true;
}
At the end of the function "ButtonClickAction" I have "finish result", but it works wrong because allValid has always "true". Help!
(sorry for bad English, it's my non-native language, I try explain correctly)
... and some server code:
var url = "https://docs.google.com/spreadsheets/d/1s8l-8N8dI-GGJi_mmYs2f_88VBcnzWfv3YHgk1HvIh0/edit?usp=sharing";
var sprSRCH = SpreadsheetApp.openByUrl(url);
let sheetSRCHSSCC = sprSRCH.getSheetByName("PUTAWAY_TO");
let sheetTSD = sprSRCH.getSheetByName("ПРИВЯЗКА МЕСТ");
function searchLogins(UserInfo){
let sheetSRCHLGN = sprSRCH.getSheetByName("ЛОГИНЫ");
let findingRLGN = sheetSRCHLGN.getRange("A:A").getValues();
let valToFind = UserInfo.zLOGIN;
for (let i = 0; i < findingRLGN.length; i++){
if(findingRLGN[i].indexOf(valToFind)!==-1){
return true;
}
};
return false;
}
function searchSSCC(UserInfo){
let findingRSSCC = sheetSRCHSSCC.getRange("M:M").getValues();
let valToFind = UserInfo.zSSCС;
for (let i = 0; i < findingRSSCC.length; i++){
if(findingRSSCC[i].indexOf(valToFind)!==-1){
return true;
break;
}
};
indx=2;
return false;
}

When pressed button in react, console log shows the result but page does not

I am new to react and web. I have an issue when calling the function console shows it but i can not show it in my page.
usePriest = (evt, id) => {
const num = 3;
const { rear,bottom2,bottom3,bottom,player1, player2, player3, player4, mycards } = this.state;
var whichPlayer;
switch(num){
case 1:
whichPlayer = player1[0];
rear[1]=whichPlayer;
rear[0]=card6;
break;
case 2:
whichPlayer = player2[0];
bottom[1]=whichPlayer;
bottom[0]=card6;
break;
case 3:
whichPlayer = player3[0];
bottom2[1]=whichPlayer;
bottom2[0]=card6;
break;
case 4:
whichPlayer = player4[0];
bottom3[1]=whichPlayer;
bottom3[0]=card6;
break;
}
// bottom[1]=whichPlayer;
// bottom[0]=card6;
// console.log(bottom);
}
and i call my function in here
else if (mycards[0]==="/static/media/priest.ae71698d.jpg") {
return ( <div>
<button className="button_card1_use" onClick={(evt) => this.usePriest(evt, 1)}>Use</button>
<button className="button_card1_discard">Discard</button>
<div className="about1"><p>Priest</p>
Player is allowed to see another player's hand. </div></div>
)
}
What should i return in function or do something in order to be able to show it on the page.
You just need to call a setState at the end of the function in order tot reflect the changes -:
usePriest = (evt, id) => {
const num = 3;
// your old code
this.setState({ rear,bottom2,bottom3,bottom,player1, player2, player3, player4, mycards })
}
Actually in JS things get copied by reference, so effectively we are mutating the state directly. This is a better solution for the same -:
usePriest = (evt, id) => {
const num = 3;
const { rear,bottom2,bottom3,bottom,player1, player2, player3, player4, mycards } = this.state;
var whichPlayer;
switch(num){
case 1:
this.setState({whichPlayer: player1[0], rear: [...rear, 0: card6, 1: whichPlayer]});
break;
case 2:
this.setState({whichPlayer: player2[0], bottom: [...bottom, 0: card6, 1: whichPlayer]});
break;
case 3:
this.setState({whichPlayer: player3[0], bottom2: [...bottom2, 0: card6, 1: whichPlayer]});
break;
case 4:
this.setState({whichPlayer: player4[0], bottom3: [...bottom3, 0: card6, 1: whichPlayer]});
break;
}
}

Error when trying to set Google Forms quiz score

I'm trying to change the grade of a response based on its answer.
Here's the code I'm using:
function myFunction() {
var form = FormApp.openById('formID123456');
// For a question with options: "1", "2", "3", and "4",
// award points for responses that correlate with their answers.
var formResponses = FormApp.getActiveForm().getResponses();
// Go through each form response
for (var i = 0; i < formResponses.length; i++) {
var response = formResponses[i];
var items = FormApp.getActiveForm().getItems();
// Assume it's the first item
var item = items[0];
var itemResponse = response.getGradableResponseForItem(item);
// Give 4 points for "4".
if (itemResponse != null && itemResponse.getResponse() == '4') {
var points = item.asScaleItem().getPoints();
itemResponse.setScore(points == 4);
}
// Give 3 points for "3".
else if (itemResponse != null && itemResponse.getResponse() == '3') {
var points = item.asScaleItem().getPoints();
itemResponse.setScore(points == 3);
}
// Give 2 points for "2".
else if (itemResponse != null && itemResponse.getResponse() == '2') {
var points = item.asScaleItem().getPoints();
itemResponse.setScore(points == 2);
}
// Give 1 points for "1".
else if (itemResponse != null && itemResponse.getResponse() == '1') {
var points = item.asScaleItem().getPoints();
itemResponse.setScore(points == 1);
// This saves the grade, but does not submit to Forms yet.
response.withItemGrade(itemResponse);
}
}
// Grades are actually submitted to Forms here.
FormApp.getActiveForm().submitGrades(formResponses);
}
This returns the error:
We're sorry, a server error occurred. Please wait a bit and try again. (line 23, file "Code")
It seemed like it was having issues changing the score of the response, but it didn't return a specific error, so I tried to isolate the part that changes the score.
Here, the script attempts only to change the score of the response.
function myFunction() {
var form = FormApp.openById('formID123456');
var formResponses = FormApp.getActiveForm().getResponses();
// Go through each form response
for (var i = 0; i < formResponses.length; i++) {
var response = formResponses[i];
var items = FormApp.getActiveForm().getItems();
// Assume it's the first item
var item = items[0];
var itemResponse = response.getGradableResponseForItem(item);
// Set Score to 3
var points = item.asScaleItem().getPoints();
itemResponse.setScore(points == 3);
}}
Again, it returned the same error, which confirms my suspicions. Why am I having this problem and how can I fix it? Any help would be much appreciated. Thanks!
As I mentioned in comments, your posted code erroneously uses a Boolean value in the call to ItemResponse#setScore, when the method expects to receive an Integer value.
Resolving the internal server error can be done by changing your entire if-elseif chain from this:
if (itemResponse != null && itemResponse.getResponse() == '4') {
var points = item.asScaleItem().getPoints();
itemResponse.setScore(points == 4); //<--- 'points == 4' evaluates to True or False
}
// Give 3 points for "3".
else if (...
to this:
// Skip changing the score if there was no answer or the answer is "falsey"
if (!itemResponse || !itemResponse.getResponse())
continue;
var answer = itemResponse.getResponse();
var newPoints = answer *1; // Convert "2" to 2, etc.
// Assumption: newPoints <= maximum possible points.
itemResponse.setScore(newPoints);
response.withItemGrade(itemResponse);
The below code is an example of how to set all graded items in all responses to a form to their maximum possible value.
function everyonePassesForTrying() {
var form = FormApp.getActiveForm();
var responses = form.getResponses();
responses.forEach(function (fr) {
fr.getGradableItemResponses().forEach(function (gr) {
if (gr.getResponse()) {
var maxPoints = getPointValue_(gr.getItem());
if (gr.getScore() !== maxPoints) {
// Re-grade the item's response.
gr.setScore(maxPoints);
// Update the form response with the new grade.
fr.withItemGrade(gr);
}
}
else { /* They didn't even try, so no change */ }
});
});
// Submit the altered scores.
form.submitGrades(responses);
}
var itemCache = {};
function getPointValue_(item) {
var id = item.getId();
// Use a pseudo-cache of the item's point values to avoid constantly determining what
// type it is, casting to that type, and getting the max points.
if(!itemCache[id]) {
// Haven't seen it yet, so cast and cache.
item = castToType_(item);
itemCache[id] = {maxPoints: item.getPoints() *1};
}
return itemCache[id].maxPoints;
}
function castToType_(item) {
// Cast the generic item to its type.
var CHECKBOX = FormApp.ItemType.CHECKBOX,
DATE = FormApp.ItemType.DATE,
DATETIME = FormApp.ItemType.DATETIME,
DURATION = FormApp.ItemType.DURATION,
LIST = FormApp.ItemType.LIST,
MULTICHOICE = FormApp.ItemType.MULTIPLE_CHOICE,
PARAGRAPH = FormApp.ItemType.PARAGRAPH_TEXT,
SCALE = FormApp.ItemType.SCALE,
TEXT = FormApp.ItemType.TEXT,
TIME = FormApp.ItemType.TIME;
switch (item.getType()) {
case CHECKBOX: item = item.asCheckboxItem();
break;
case DATE: item = item.asDateItem();
break;
case DATETIME: item = item.asDateTimeItem();
break;
case DURATION: item = item.asDurationItem();
break;
case LIST: item = item.asListItem();
break;
case MULTICHOICE: item = item.asMultipleChoiceItem();
break;
case PARAGRAPH: item = item.asParagraphTextItem();
break;
case SCALE: item = item.asScaleItem();
break;
case TEXT: item = item.asTextItem();
break;
case TIME: item = item.asTimeItem();
break;
default:
throw new Error("Unhandled gradable item type '" + item.getType() + "'");
break;
}
return item;
}

Parse URL (ActionScript 3.0)

I would like to know how would one parse an URL.
protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes
I need to get "this_is_what_i_want/even_if_it_has_slashes"
How should I do this?
Thanks!
Try this :
var u:String = 'protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes',
a:Array = u.split('/'),
s:String = ''
for(var i=0; i<a.length; i++){
if(i > 3){
s += '/'+a[i]
}
}
trace(s) // gives : /morethings/this_is_what_i_want/even_if_it_has_slashes
Another approach would be using Regex like this:
.*?mydomain\.com[^\/]*\/[^\/]+\/[^\/]+\/([^?]*)
(Breakdown of the components.)
This looks for a pattern where it skips whatever comes before the domain name (doesn't matter if the protocol is specified or not), skips the domain name + TLD, skips any port number, and skips the first two sub path elements. It then selects whatever comes after it but skips any query strings.
Example: http://regexr.com/39r69
In your code, you could use it like this:
var url:String = "protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes";
var urlExp:RegExp = /.*?mydomain\.com[^\/]*\/[^\/]+\/[^\/]+\/([^?]*)/g;
var urlPart:Array = urlExp.exec(url);
if (urlPart.length > 1) {
trace(urlPart[1]);
// Prints "this_is_what_i_want/even_if_it_has_slashes"
} else {
// No matching part of the url found
}
As you can see on the regexr link above, this captures the part "this_is_what_i_want/even_if_it_has_slashes" for all of these variations of the url:
protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes
protocol://mydomain.com:8080/something/morethings/this_is_what_i_want/even_if_it_has_slashes
protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes.html
protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes.html?hello=world
mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes
protocol://subdomain.mydomain.com:8080/something/morethings/this_is_what_i_want/even_if_it_has_slashes
Edit: Fixed typo in regexp string
Simple way,
var file:String = 'protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes';
var splitted:Array = file.split('/');
var str1:String = splitted.splice(3).join('/'); //returns 'something/morethings/this_is_what_i_want/even_if_it_has_slashes'
var str1:String = splitted.splice(5).join('/'); //returns 'this_is_what_i_want/even_if_it_has_slashes'
If you want to be a little more flexible in the feature (e.g. you need the domain), you can use my Url class.
Class for URL parsing
package
{
import flash.net.URLVariables;
public class Url
{
protected var protocol:String = "";
protected var domain:String = "";
protected var port:int = 0;
protected var path:String = "";
protected var parameters:URLVariables;
protected var bookmark:String = "";
public function Url(url:String)
{
this.init(url);
}
protected function splitSingle(value:String, c:String):Object
{
var temp:Object = {first: value, second: ""};
var pos:int = value.indexOf(c);
if (pos > 0)
{
temp.first = value.substring(0, pos);
temp.second = value.substring(pos + 1);
}
return temp;
}
protected function rtrim(value:String, c:String):String
{
while (value.substr(-1, 1) == c)
{
value = value.substr(0, -1);
}
return value;
}
protected function init(url:String):void
{
var o:Object;
var urlExp:RegExp = /([a-z]+):\/\/(.+)/
var urlPart:Array = urlExp.exec(url);
var temp:Array;
var rest:String;
if (urlPart.length <= 1)
{
throw new Error("invalid url");
}
this.protocol = urlPart[1];
rest = urlPart[2];
o = this.splitSingle(rest, "#");
this.bookmark = o.second;
rest = o.first;
o = this.splitSingle(rest, "?");
o.second = this.rtrim(o.second, "&");
this.parameters = new URLVariables();
if (o.second != "")
{
try
{
this.parameters.decode(o.second);
}
catch (e:Error)
{
trace("Warning: cannot decode URL parameters. " + e.message + " " + o.second);
}
}
rest = o.first
o = this.splitSingle(rest, "/");
if (o.second != "")
{
this.path = "/" + o.second;
}
rest = o.first;
o = this.splitSingle(rest, ":");
if (o.second != "")
{
this.port = parseInt(o.second);
}
else
{
switch (this.protocol)
{
case "https":
this.port = 443;
break;
case "http":
this.port = 80;
break;
case "ssh":
this.port = 22;
break;
case "ftp":
this.port = 21;
break;
default:
this.port = 0;
}
}
this.domain = o.first;
}
public function getDomain():String
{
return this.domain;
}
public function getProtocol():String
{
return this.protocol;
}
public function getPath():String
{
return this.path;
}
public function getPort():int
{
return this.port;
}
public function getBookmark():String
{
return this.bookmark;
}
public function getParameters():URLVariables
{
return this.parameters;
}
}
}
Example usage
try {
var myUrl:Url = new Url("protocol://mydomain.com/something/morethings/this_is_what_i_want/even_if_it_has_slashes");
trace("Protocol: " + myUrl.getProtocol());
trace("Domain: " + myUrl.getDomain());
trace("Path: " + myUrl.getPath());
trace("What you want: " + myUrl.getPath().split("/").splice(2).join("/") );
} catch (e:Error) {
trace("Warning: cannot parse url");
}
Output
Protocol: protocol
Domain: mydomain.com
Path: /something/morethings/this_is_what_i_want/even_if_it_has_slashes
What you want: morethings/this_is_what_i_want/even_if_it_has_slashes
Description
The init function checks with the regular expression if the given url starts with some letters (the protocol) followed by a colon, two slashes and more characters.
If the url contains a hash letter, everything behind its fist occurrence is taken as a bookmark
If the url contains a question mark, everything behind its fist occurrence is taken as key=value variables and parsed by the URLVariables class.
If the url contains a slash, everything behind its first occurrence is taken as the path
If the rest (everything between the last protocol slash and the first slash of the path) contains a colon, everything behind it will be converted to an integer and taken as the port. If the port is not set, a default will be set in dependency of the protocol
The rest is the domain
For answering your question, I use the path of the given url, split it by slash, cut of the 'something' and join it by slash.

my google apps script doesn't run, no parameters with serverhandler

I try to change a sheets with a script but it doesn't work as expected. I can load the right panel, but nothing happens when I try to record the change. It seems "masterFunctionPS" isn't called.
The function periodSelection post the panel, the listbox and the button. But nothing append, when I clic on the Button. Nothing change in the sheets.
function periodSelection() {
var activeSS = SpreadsheetApp.getActiveSpreadsheet();
var sheetPS = activeSS.getSheetByName("Periods");
var uiPS = UiApp.createApplication().setWidth(300);
var panelPS = uiPS.createVerticalPanel();
var periodPS = uiPS.createListBox();
for (var i = 2; i < 13; i++) {
var range = "A" + i;
periodPS.addItem(sheetPS.getRange(range).getValue());
}
var endDatePS = uiPS.createDatePicker();
var recordPS = uiPS.createButton("Enregistrer");
var masterPS = uiPS.createServerHandler('masterFunctionPS');
masterPS.addCallbackElement(periodPS)
.addCallbackElement(endDatePS)
recordPS.addClickHandler(masterPS);
panelPS.add(periodPS);
panelPS.add(endDatePS);
panelPS.add(recordPS);
uiPS.add(panelPS);
SpreadsheetApp.getUi().showSidebar(uiPS);
return uiPS;
}
function masterFunctionPS(element) {
var parameterPS = element.parameter;
var appE = UiApp.getActiveApplication();
var periodE = parameterPS.periodPS;
var endDateE = parameterPS.endDatePS;
var activeE = parameterPS.activeSS;
var sheetE = parameterPS.sheetPS;
switch (periodE) {
case "P1":
sheetE.getRange("C2").setValue(endDateE);
break;
case "P2":
sheetE.getRange("C3").setValue(endDateE);
break;
case "P3":
sheetE.getRange("C4").setValue(endDateE);
break;
case "P4":
sheetE.getRange("C5").setValue(endDateE);
break;
case "P5":
sheetE.getRange("C6").setValue(endDateE);
break;
case "P6":
sheetE.getRange("C7").setValue(endDateE);
break;
case "P7":
sheetE.getRange("C8").setValue(endDateE);
break;
case "P8":
sheetE.getRange("C9").setValue(endDateE);
break;
case "P9":
sheetE.getRange("C10").setValue(endDateE);
break;
case "10":
sheetE.getRange("C11").setValue(endDateE);
break;
case "P11":
sheetE.getRange("C12").setValue(endDateE);
break;
}
return (appE);
}
There are a few errors in your code...mainly you forgot to give names to your widgets and name is used to retrieve values from the callbackelements
below is a "rectified" version that works but there are still 2 items that won't work because you tried to get properties of the sheet in the Ui and that can't be done like this...
please explain what for you need that and I could suggest a better way to go.
(see comments in code and look at the logger to see the values in event parameters)
function periodSelection() {
var activeSS = SpreadsheetApp.getActiveSpreadsheet();
var sheetPS = activeSS.getActiveSheet();
var uiPS = UiApp.createApplication();
var panelPS = uiPS.createVerticalPanel();
var periodPS = uiPS.createListBox().setName('periodPS');
for (var i = 2; i < 13; i++) {
var range = "A" + i;
periodPS.addItem(sheetPS.getRange(range).getValue());
}
var endDatePS = uiPS.createDatePicker().setName('endDatePS');
var recordPS = uiPS.createButton("Enregistrer");
var masterPS = uiPS.createServerHandler('masterFunctionPS');
masterPS.addCallbackElement(panelPS);
recordPS.addClickHandler(masterPS);
panelPS.add(periodPS);
panelPS.add(endDatePS);
panelPS.add(recordPS);
uiPS.add(panelPS);
SpreadsheetApp.getUi().showSidebar(uiPS);
}
function masterFunctionPS(element) {
var parameterPS = element.parameter;
var appE = UiApp.getActiveApplication();
Logger.log('parameter : '+JSON.stringify(parameterPS));
var periodE = parameterPS.periodPS;
var endDateE = parameterPS.endDatePS;
var activeE = parameterPS.activeSS; // won't work
var sheetE = parameterPS.sheetPS; // won't work
switch (periodE) {
case "P1":
sheetE.getRange("C2").setValue(endDateE);
break;
case "P2":
sheetE.getRange("C3").setValue(endDateE);
break;
case "P3":
sheetE.getRange("C4").setValue(endDateE);
break;
case "P4":
sheetE.getRange("C5").setValue(endDateE);
break;
case "P5":
sheetE.getRange("C6").setValue(endDateE);
break;
case "P6":
sheetE.getRange("C7").setValue(endDateE);
break;
case "P7":
sheetE.getRange("C8").setValue(endDateE);
break;
case "P8":
sheetE.getRange("C9").setValue(endDateE);
break;
case "P9":
sheetE.getRange("C10").setValue(endDateE);
break;
case "10":
sheetE.getRange("C11").setValue(endDateE);
break;
case "P11":
sheetE.getRange("C12").setValue(endDateE);
break;
}
return appE;
}
EDIT :
I think I guess what you are trying to do...
Actually the active SS and sheet are always the same, you can just reuse it the same way ...(personally I would keep the same names all along...) see updated handler function below :
function masterFunctionPS(element) {
var parameterPS = element.parameter;
var appE = UiApp.getActiveApplication();
Logger.log('parameter : '+JSON.stringify(parameterPS));
var periodE = parameterPS.periodPS;
var endDateE = parameterPS.endDatePS;
// var activeE = parameterPS.activeSS; // won't work
// var sheetE = parameterPS.sheetPS; // won't work
var activeE = SpreadsheetApp.getActiveSpreadsheet();
var sheetE = activeE.getActiveSheet();
switch (periodE) {
case "P1":
sheetE.getRange("C2").setValue(endDateE);
break;
case "P2":
sheetE.getRange("C3").setValue(endDateE);
break;
case "P3":
sheetE.getRange("C4").setValue(endDateE);
break;
case "P4":
sheetE.getRange("C5").setValue(endDateE);
break;
case "P5":
sheetE.getRange("C6").setValue(endDateE);
break;
case "P6":
sheetE.getRange("C7").setValue(endDateE);
break;
case "P7":
sheetE.getRange("C8").setValue(endDateE);
break;
case "P8":
sheetE.getRange("C9").setValue(endDateE);
break;
case "P9":
sheetE.getRange("C10").setValue(endDateE);
break;
case "10":
sheetE.getRange("C11").setValue(endDateE);
break;
case "P11":
sheetE.getRange("C12").setValue(endDateE);
break;
}
// the following line is only for test... remove it when it works!!!
sheetE.getRange("A1").setValue('failed to write value '+endDateE);
return appE;
}