Sabtu, 10 Desember 2016

gogle form trigger on submit

//==============================================
/**
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function myFunction() {
  var triggers = ScriptApp.getProjectTriggers();
  for(var i in triggers) {
    ScriptApp.deleteTrigger(triggers[i]);
  }
  ScriptApp.newTrigger("SendHold")
  .forForm(FormApp.getActiveForm())
  .onFormSubmit()
  .create();
}

//=========================================================

function SendHold(e)
{
  try
  {
    //====== MSA LALALU
    var message = "";
    var s = FormApp.getActiveForm().getResponses();
    var items = s[s.length-1].getItemResponses();
    for (var j = 0; j < items.length; j++) {
      var item = items[j];
      message+= item.getItem().getTitle() + "=" + item.getResponse()+ "\n";
      Logger.log('Response #%s to the question "%s" was "%s"',(s.length).toString(),item.getItem().getTitle(),item.getResponse());
    }
    //====== MSA LALALU
    /*
    var s = FormApp.getActiveForm().getResponses();
    var message = "";
    for (var i = 0; i < s.length; i++) {
     
      message='';
      var items = s[i].getItemResponses();
      for (var j = 0; j < items.length; j++) {
        var item = items[j];
        message+= item.getItem().getTitle() + "=" + item.getResponse()+ "\n";
         Logger.log('Response #%s to the question "%s" was "%s"',(i + 1).toString(),item.getItem().getTitle(),item.getResponse());
      }
    }
    */
    GmailApp.sendEmail("xxxxx@gmail.com", "form test","isi" + "\n" +message,{name: 'Form Layanan Desa'})
 
  } catch (e) {
    Logger.log(e.toString());
    MailApp.sendEmail("xxxxx@gmail.com","err log",e.toString() + '\n' + msg);
  }
}

//===================================================

Tidak ada komentar:

Posting Komentar

Foto Propades