I have this html application which will look for a certain ID number then it will populate the field in the userform. Once I click the button Update Data, I am hoping that it will update the specific row values in the google sheet, but I always end up getting Uncaught at updateProfile (fcn:81). "(fcn:81)" end up to be var newDataRow = ws.getRange(myPnum + 1, 1, 1, ws.getLastColumn()).setValues(...
Here is my javascript code:
document.getElementById("updatebtn").addEventListener("click", updateAppProfile);
//---------------------- UPDATE PROFILE ---------------------------------//
function updateAppProfile(){
var upProfile = document.getElementById("profileNum").value;
if(upProfile.length === 6){
var myNewData = {};
myNewData.profnum = document.getElementById("profileNum").value;
myNewData.firstName = document.getElementById("fname").value;
myNewData.middleName = document.getElementById("mname").value;
myNewData.lastName = document.getElementById("lname").value;
myNewData.appsex = document.getElementById("sex").value;
myNewData.civStat = document.getElementById("cstatus").value;
myNewData.citizen = document.getElementById("citizenship").value;
myNewData.birthdate = document.getElementById("bdate").value;
// console.log(myNewData);
// alert("OK");
google.script.run.updateMyProfile(upProfile,myNewData);
}
else{
alert("invalid Profile Number");
}
}
</script>
Here is my google app script function:
function updateMyProfile(upProfile,myNewData){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ws = ss.getSheetByName("Results");
var data = ws.getRange(1, 1, ws.getLastRow(), 1).getValues();
var dJoin = data.join().split(",");
var myPnum = dJoin.indexOf(upProfile);
if (myPnum > -1){
var newDataRow = ws.getRange(myPnum + 1, 1, 1, ws.getLastColumn()).setValues([[myNewData.profnum,
myNewData.firstName,
myNewData.middleName,
myNewData.lastName,
myNewData.appsex,
myNewData.civStat,
myNewData.citizen,
myNewData.birthdate
]]);
} else {
Logger.log("unknown data")
}
}
I don't know what to do since when I test the data on the google script side only it work. But when I used the whole program it ends up in that error. I hope anyone can help. Thank you in advance. I will really appreciate your answers. thank you.