I am have an App Script that has some functions that are triggered on form submit. I am wanting to remove all dashes from a submitted field (telephone number) and save them back to the sheet with the dashes removed. I have been playing with the code for awhile and cannot get it to work, although I am doing something similar on another sheet. In this case the column number for the data i need to rewrite is column 10.
function sanitizePhoneNumber(columnIndex) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = sheet.getLastRow();
var cell = sheet.getRange(lastRow,columnIndex);
var sanitizedData = cell.getValue().toString().replace("-","");
cell.setValue(sanitizedData);
}
function onSubmit(e) {
sanitizePhoneNumber(10);
}