Inside the handler function bellow I'm trying to store and get the value of an array of arrays named "theses":
var fact_list = [ ["Kennedy Inauguration", "politics", "tZwnNdFNkNklYc3pVUzZINUV4eUtWVWFSVEf"], ["Pericles’ Funeral Oration", "politics", "sdgrewaNkNklYc3pVUzZINUV4eUtW345ufaZ"], ["The Pleasure of Books", "culture", "1234rFszdgrfYc3pVUzZINUV4eU43usacd"], ["I Am The First Accused (Nelson Mandela)", "law", "34rsgadOsidjSZIswjadi95uydnfklsdks"] ];
function submit(e){
Logger.log("running submit(e)");
var numberOfItems = e.parameter.checkbox_total;
var itemsSelected = [];
// for each item, if it is checked / selected, add it to itemsSelected
for(var i = 0; i < numberOfItems; i++){
if(e.parameter['checkbox_isChecked_'+i] == 'true'){
itemsSelected.push(e.parameter['checkbox_value_'+i]);
}
}
var app = UiApp.getActiveApplication();
Logger.log("itemsSelected = " + itemsSelected);
ScriptProperties.setProperties({'theses': itemsSelected}, true);
var thesesArrays = ScriptProperties.getProperty('theses');
Logger.log("thesesArrays = " + thesesArrays);
for (var i = 0; i < thesesArrays.lenght(); i++){
var thesesId = ScriptProperties.getProperty('theses')[i][2];
var thesesType = ScriptProperties.getProperty('theses')[i][1];
importTheses(target, thesesId, thesesType);
}
app.close();
return app;
}
But when the code gets the line for (var i = 0; i < thesesArrays.lenght(); i++){
I got an error, because thesesArrays
is not an array of arrays (as I intended) but an object which doesn't have the lenght()
method.
How can I fix that? How can I store and retrieve an array in ScriptProperties?
Inside the handler function bellow I'm trying to store and get the value of an array of arrays named "theses":
var fact_list = [ ["Kennedy Inauguration", "politics", "tZwnNdFNkNklYc3pVUzZINUV4eUtWVWFSVEf"], ["Pericles’ Funeral Oration", "politics", "sdgrewaNkNklYc3pVUzZINUV4eUtW345ufaZ"], ["The Pleasure of Books", "culture", "1234rFszdgrfYc3pVUzZINUV4eU43usacd"], ["I Am The First Accused (Nelson Mandela)", "law", "34rsgadOsidjSZIswjadi95uydnfklsdks"] ];
function submit(e){
Logger.log("running submit(e)");
var numberOfItems = e.parameter.checkbox_total;
var itemsSelected = [];
// for each item, if it is checked / selected, add it to itemsSelected
for(var i = 0; i < numberOfItems; i++){
if(e.parameter['checkbox_isChecked_'+i] == 'true'){
itemsSelected.push(e.parameter['checkbox_value_'+i]);
}
}
var app = UiApp.getActiveApplication();
Logger.log("itemsSelected = " + itemsSelected);
ScriptProperties.setProperties({'theses': itemsSelected}, true);
var thesesArrays = ScriptProperties.getProperty('theses');
Logger.log("thesesArrays = " + thesesArrays);
for (var i = 0; i < thesesArrays.lenght(); i++){
var thesesId = ScriptProperties.getProperty('theses')[i][2];
var thesesType = ScriptProperties.getProperty('theses')[i][1];
importTheses(target, thesesId, thesesType);
}
app.close();
return app;
}
But when the code gets the line for (var i = 0; i < thesesArrays.lenght(); i++){
I got an error, because thesesArrays
is not an array of arrays (as I intended) but an object which doesn't have the lenght()
method.
How can I fix that? How can I store and retrieve an array in ScriptProperties?
Share Improve this question edited Jun 6, 2018 at 2:03 Wicket 38.5k9 gold badges78 silver badges193 bronze badges asked Dec 13, 2013 at 13:38 craftApprenticecraftApprentice 2,77720 gold badges61 silver badges87 bronze badges2 Answers
Reset to default 12The other answer only deals with the syntax error on length. But it still wont work because you can only store strings in scriptProperties.
1) json.stringify your array to store it as string
2) dont call getProperty a million times. Call it once before the loop and json.parse it into an array.
In javascript, you can't do
array.length();
You need to delete the () because length() don't exist !
EDIT:
And if it's returning an array of array of object, you could do a function that transform the array of object into an array of your specific object by looping it, then create your object and setting it's properties like this for example:
this.name = object['name'];