我可以在Google Apps Script MailApp中执行条件语句吗?

时间:2018-07-26 17:42:42

标签: google-apps-script conditional

我认为这将非常简单,但是我无法在MailApp中工作。我要做的只是通过电子邮件发送由表单创建的地址,如果有“ address2”条目来添加该行。如果没有条件,大多数地址将在电子邮件中有换行符。我想要类似下面的代码,但是Google Script不允许我保存它,因为if语句抛出语法错误。

MailApp.sendEmail({
to: "johndoe@gmail.com",
subject: "New Client",
htmlBody: "<p>New Client</p>" +
    "<p>Contact Name: " + ContactName + "<br>" +
    "Address:<br>" +
    "<br>" +
    address1 + "<br>" +
if(address2 !== 0)
    {address2 + "<br>" +}
    city + "," + state + zip "</p>".
});

请告知。谢谢你。

1 个答案:

答案 0 :(得分:0)

#!/usr/bin/env groovy

pipeline {
    agent any
    options {
        timestamps()
    }
    triggers {
        bitbucketPush()
    }
    stages {
        stage('Build project A') {
            when {
                changeset "project-a/**"
            }
            steps {
                build 'project-a'
            }
        }
        stage('Build project B') {
            when {
                changeset "project-b/**"
            }
            steps {
                build 'project-b'
            }
        }
    }
}

无效的JavaScript。 if语句不是可以在公式中使用的运算符;这就是三元运算符"<br>" + if(address2 !== 0) {address2 + "<br>" +} city + "," + state + zip "</p>" 的作用。示例:

condition ? if_true : if_false
相关问题