Reputation: 131
I am trying to check duplicate from org array with chg array. If there is no duplicate push value to temp array.
function uList(org, chg){
//return a unique list
var org ;
var chg ;
var temp ;
for(var i=0;i<=org.legnth;i++){
for(var j=0;j<=chg.length;j++){
if(org[i][0]==chg[j][0]){
if(temp.length>0) {temp.pop();}
}else{
temp.push(org[i][0]);
}
}
}
return temp;
}
Entire Code is show below.
function onEdit(e){
// Browser.msgBox("test");
updateForm();
}
function uList(org, chg){
//return a unique list
var org ;
var chg ;
var temp ;
for(var i=0;i<=org.legnth;i++){
for(var j=0;j<=chg.length;j++){
if(org[i][0]==chg[j][0]){
if(temp.length>0) {temp.pop();}
}else{
temp.push(org[i][0]);
}
}
}
return temp;
}
function updateForm(){ // select list from name
// call your form and connect to the drop-down item
var form = FormApp.openById("");
var namesList = form.getItemById("").asListItem(); //data-item-id
// identify the sheet where the data resides needed to populate the drogp-down// Mask_order (responses)
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/').getSheetByName("");
var names =ss;
var namesValues =names.getRange("F2:F").getValues();//desired dorpdown list
var total=names.getRange("H2").getValue();//Define COUNTA
var org_list=names.getRange("E2:E").getValues();//original list
var chg_list=names.getRange("D2:D").getValues();//Redeem list
var the_list=uList(org_list,chg_list);
//var thelist=uList(org_list,chg_list);
// names.getRange("F2").setValue("2");
var temp=form.getItemById("").setHelpText("No. of :"+total)// Mask redeem help text.
debugger;
var studentNames = [];
// convert the array ignoring empty cells
for(var i = 0; i < namesValues.length; i++)
if(namesValues[i][0] != "")
studentNames[i] = namesValues[i][0];
// populate the drop-down with the array data
namesList.setChoiceValues(studentNames);
}
In Google script Debug mode, a temp is an object with no data.
I attempted to put debugger everywhere and it did not enter the for loop.
to put the for loop inside updateForm(), It does not run.
to put create a demo function, I could access and pass data to different functions.
Upvotes: 0
Views: 330
Reputation: 131
A typo that caused the mistake..... org.legnth --> should be org.length I am attempting to get the array length
function uList(org, chg){
//return a unique list
var org ;
var chg ;
var temp ;
for(var i=0;i<=org.legnth;i++){
for(var j=0;j<=chg.length;j++){
if(org[i][0]==chg[j][0]){
if(temp.length>0) {temp.pop();}
}else{
temp.push(org[i][0]);
}
}
}
return temp;
}
Change to
function uList(org, chg){
//return a unique list
var org ;
var chg ;
var temp=[] ;
for(var i=0;i<=org.legnth;i++){
for(var j=0;j<=chg.length;j++){
if(org[i]==chg[j]){
if(temp.length>0) {temp.pop();}
}else{
temp.push(org[i][0]);
}
}
}
return temp;
}
Change log:
2020-01-30 0023 GMT+8
Upvotes: 1