0
我很抱歉。我確信這是一個菜鳥問題,只是一個簡單的答案。錯誤與電子郵件通知腳本中的「null」字段
因此,我使用以下內容在用戶創建條目時發送電子郵件通知。一切正常,除了兩個與「空白」條目相關的行爲。
function newSalesEmailMessage(sendButton) {
var pageWidgets = sendButton.root.descendants;
var fullName = app.datasources.CurrentUser.item.FullName;
var htmlbody = '<b><font size="3">' + fullName + '</font></b>' + ' has created a new sales entry for: ' +
'<h1><span style="color:#2196F3">' + pageWidgets.ShowName.value + '</h1>' +
'<p>Shoot Date: <b>' + pageWidgets.ProjectDate.value.toDateString() + '</b>' +
'<p>Contact: <b>' + pageWidgets.Contact.value + '</b>' +
'<p>Post AP: <b>' + pageWidgets.PostAP.value + '</b>' +
'<p>Sales Person: <b>' + pageWidgets.SalesPerson.value + '</b>' +
'<p>Notes: <b>' + pageWidgets.Notes.value + '</b>';
google.script.run
.withSuccessHandler(function() {
})
.withFailureHandler(function(err) {
console.error(JSON.stringify(err));
})
.sendEmailCreate(
'[email protected]',
'New Sales Entry for: ' + pageWidgets.ShowName.value,
htmlbody);
return sendButton === "" || sendButton === null || sendButton === undefined;
}
問題1:當用戶離開領域的空白電子郵件把在外地,這是有道理的「空」,但人們不斷地問我:「誰是空?」啊。
所以,如果有一種方法來輸出一個空白(例如:「」)而不是「空」,那將是很棒的。
問題2:每當用戶離開ProjectDate(這是一個日期字段)空白我得到的錯誤:無法讀取屬性'toDateString'null。
這很有道理,但顯然這會導致此腳本無法完成。我希望像這樣會解決這兩個問題,但它沒有:
function newSalesEmailMessage(sendButton) {
var pageWidgets = sendButton.root.descendants;
if (pageWidgets === null) {
pageWidgets = "";
}
var fullName = app.datasources.CurrentUser.item.FullName;
var htmlbody = '<b><font size="3">' + fullName + '</font></b>' + ' has created a new sales entry for: ' +
'<h1><span style="color:#2196F3">' + pageWidgets.ShowName.value + '</h1>' +
'<p>Shoot Date: <b>' + pageWidgets.ProjectDate.value.toDateString() + '</b>' +
'<p>Contact: <b>' + pageWidgets.Contact.value + '</b>' +
'<p>Post AP: <b>' + pageWidgets.PostAP.value + '</b>' +
'<p>Sales Person: <b>' + pageWidgets.SalesPerson.value + '</b>' +
'<p>Notes: <b>' + pageWidgets.Notes.value + '</b>';
google.script.run
.withSuccessHandler(function() {
})
.withFailureHandler(function(err) {
console.error(JSON.stringify(err));
})
.sendEmailCreate(
'[email protected]',
'New Sales Entry for: ' + pageWidgets.ShowName.value,
htmlbody);
}
謝謝你的幫助。
這工作。非常感謝你。 –