从另一个功能触发功能

时间:2014-06-12 16:03:40

标签: javascript google-apps-script

嗨我在Apps脚本中有两个功能,当第一个功能完成时,我想要触发第二个功能,是否可能?

function sendEmail() {

 var firstThread = GmailApp.getInboxThreads(0,1)[0];
 var message = firstThread.getMessages()[0];
 var sender = message.getFrom();
  var body = "Detta mail är ursprungligen skickat från" + " " + sender + '\n' + message.getBody();
 var subject = message.getSubject();
 var attachment = message.getAttachments();
  GmailApp.sendEmail("user.name@adje.com", subject, "",  {htmlBody: body, attachments: attachment});

  Logger.log(body);
}

function markArchivedAsRead() {
  var threads = GmailApp.search('label:unread -label:inbox');
  GmailApp.markThreadsRead(threads);
};

1 个答案:

答案 0 :(得分:0)

正如Henrique所说,你只需要调用你所做的功能,如下所示

 function sendEmail() {
     var firstThread = GmailApp.getInboxThreads(0,1)[0];
     var message = firstThread.getMessages()[0];
     var sender = message.getFrom();
     var body = "Detta mail är ursprungligen skickat från" + " " + sender + '\n' + message.getBody();
     var subject = message.getSubject();
     var attachment = message.getAttachments();
     GmailApp.sendEmail("user.name@adje.com", subject, "",  {htmlBody: body, attachments: attachment});

     Logger.log(body);
     markArchivedAsRead();
    }

    function markArchivedAsRead() {
      var threads = GmailApp.search('label:unread -label:inbox');
      GmailApp.markThreadsRead(threads);
    };