0
votes

I have the following java which submits a simple form with some data into an Google sheet when the user submitting the new target, I wish him to receive two confirmations, one as an email sent to him, and one as a window acknowledging the receiving of the new data.

However, although I tried several times, the two functions sendemail and openDialogSuccess are not responding.

    function doGet() {
  return HtmlService.createHtmlOutputFromFile('set_or_targets')
  .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function close() {
  google.script.host.close()
}

function openDialog() {

var html = HtmlService.createHtmlOutputFromFile('set_or_targets')
      .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setHeight(650);

  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showModalDialog(html,' ');
}

function sendemail(e) {
  var userEmail = Session.getActiveUser().getEmail(); //email of the user
  var subject = "Form submitted"; //the email subject
  var d = new Date(); // the data of the update
  if (d.getHours() >= 17) {
    var ontime = "Because you updated the target after 17:00 your target will be updated in two days";
          } else {
            var ontime = 'Your update was recorded and will take into consideration starting tomorrow';
          }  // this check if the update happened before or after 17:00
  var message = "Thank you, " + userEmail + " For submitting a new Target on " + d + " " + ontime;
  MailApp.sendEmail(userEmail, subject, message);
}

function openDialogSuccess(e){
    var html = HtmlService.createHtmlOutputFromFile('Thank_You')
      .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showModalDialog(html,' ');
}
function SetTarget(formObject){
  var AT = formObject.AT;
  var BE = formObject.BE;
  var CH = formObject.CH;
  var DE = formObject.DE;
  var DK = formObject.DK;
  var ES = formObject.ES;
  var FI = formObject.FI;
  var FR = formObject.FR;
  var IT = formObject.IT;
  var NL = formObject.NL;
  var NO = formObject.NO;
  var PL = formObject.PL;
  var SE = formObject.SE;
  var UK = formObject.UK;

  var ios = formObject.ios;
  var android = formObject.android;
  var windows = formObject.windows;


  var Target=formObject.TargetOR;
  var user=Session.getActiveUser().getEmail();

  var d = new Date();

  var ss = SpreadsheetApp.openById('aa');  
  var outputSheet = ss.getSheetByName('Responses');
  var r = outputSheet.getLastRow()+1;

  if(ios=='on'){CheckCountries('IOS')};      

  if(android=='on'){CheckCountries('Android')};      

  if(windows=='on'){CheckCountries('Windows')};      

  function CheckCountries(objective){  
    if(AT== 'on') {AddData('AT',objective)};
    if(BE== 'on') {AddData('BE',objective)};
    if(CH== 'on') {AddData('CH',objective)};
    if(DE== 'on') {AddData('DE',objective)};
    if(DK== 'on') {AddData('DK',objective)};
    if(ES== 'on') {AddData('ES',objective)};
    if(FI== 'on') {AddData('FI',objective)};
    if(FR== 'on') {AddData('FR',objective)};
    if(IT== 'on') {AddData('IT',objective)};
    if(NL== 'on') {AddData('NL',objective)};
    if(NO== 'on') {AddData('NO',objective)};
    if(PL== 'on') {AddData('PL',objective)};
    if(SE== 'on') {AddData('SE',objective)};
    if(UK== 'on') {AddData('UK',objective)};
  }; 


  function AddData(country, objective){
    outputSheet.getRange(r, 1).setValue(d)
    outputSheet.getRange(r, 2).setValue(Session.getActiveUser().getEmail());
    outputSheet.getRange(r, 3).setValue(country);
    outputSheet.getRange(r, 4).setValue(objective);  
    outputSheet.getRange(r, 5).setValue(Target);
    r=r+1
  };

  doGet();

}

thanks for the help

1
The code isn't Java, it's Google Apps Script / JavaScript. - Rubén

1 Answers

-1
votes

Needed to call the function at the end of the SetTarget function