0
votes

The goal I am trying to achieve is to retrieve a cell value based on a form radio selection and update a text area.

Process: User opens dialog box. They select a field office. Onclick runs the function check. After check runs google.script.run.withSuccessHandler(addSignatureLine).getSignatureLine(cellElement); is supposed to run and update the textarea with the Id 'AdditionalMessage' with the signature line retrieved from .getSignatureLine.

Here are two functions of the html code:

<script>
function addSignatureLine(signatureLine){
  document.getElementById('AdditionalMessage').value = '\n\n'signatureLine;
};

function updateSignatureLine() {
 var cellElement = document.getElementById('ET');
  console.log('cellElement: ' + cellElement);

  google.script.run.withSuccessHandler(addSignatureLine)
    .getSignatureLine(cellElement);
};

function check() {
  var ele = document.getElementsByName('fieldOfficeET');
  var flag = 0;
  
  for (var i = 0; i < ele.length; i++) {
    if (ele[i].checked)
      flag = 1;

  }
  if (flag == 1)
    document.getElementById('Submit').disabled = false;

};
</script>

Here is the getSignatureLine.gs script

function getSignatureLine(cellObject) {
  var ss = SpreadsheetApp.openById('googleSheetId');
  var sheet = ss.getSheetByName('AMS Contact Information');
  var firstRow = 2;
  var lastRow = 10;
  var dataRange = sheet.getRange(firstRow, 1, lastRow, 11);
  var dataValues = dataRange.getValues();

  for (var key in cellObject) { //Loop through all the data in the form
    Logger.log('key: ' + key);
    Logger.log('value: ' + cellObject[key]);
  }

  //Determines the row the Field Office is in
  for (var rr = 0; rr < dataValues.length; rr++) {
    if (dataValues[rr][0] == cellObject.fieldOfficeET) {
      var r = rr + 2
      break;
    }
  }

  var signatureLine = sheet.getRange(r, 11).getValue();
  Logger.log("signatureLine: " + signatureLine)
  return signatureLine;
}
1
Where does the code fail? We can't debug your code for you. There's no way anyone can know what the values are that are being retrieved and passed around. I see that you have Logger.log statements, so are you getting unexpected values? Is cellElement correct before it's passed to the server? Use a console.log('cellElement: ' + cellElement); statement to print a value to the browser console. - Alan Wells
I added the console.log to the script and getting Uncaught SyntaxError: Unexpected identifier and Uncaught ReferenceError: check is not defined - William Welch
@SandyGood I created the function updateSignatureLine, removed the check from the onclick in the html and got the error Uncaught ReferenceError: updateSignatureLine is not defined. I'm guessing this is where the code is failing. - William Welch
Ok. There is an error in your HTML. It was "Uncaught". It just means that the code editor didn't catch it, but when the browser attempted to display the HTML, it found an error. Search for "check". Find "check", and look for possible errors. Comment out code if you need to, and go through a process of elimination. - Alan Wells
I don't see updateSignatureLine anywhere in the code that you provided. - Alan Wells

1 Answers

1
votes

There is a problem with this line:

document.getElementById('AdditionalMessage').value = '\n\n'signatureLine;

I would try:

document.getElementById('AdditionalMessage').value = '\n\n' + signatureLine;

Add a plus sign to concatenate the text.