我写了这个简单的代码来在套件脚本 2.0 中发送电子邮件,但出现错误“email.send is not a function” /** * @NApiVersion 2.x * @NScriptType ClientScript */ 定义(['N/运行时','N/搜索','N/email'],函数(运行时,电子邮件){ 函数 pageInit(context) {
if (context.mode === 'edit') {
var message = "you dont have phonenumber!";
var phone = context.currentRecord.getValue({
fieldId: 'phone'
});
if (!phone) {
alert(message);
}
}
}
function fieldChanged(context) {
var record = context.currentRecord;
var myUser = runtime.getCurrentUser().name;
try {
var myrec = record.getValue({
fieldId: 'custbody_sor_ordercategory'
});
if (myrec == 1) {
record.setValue({
fieldId: 'custbody_sor_temptest',
value: myUser
});
} else {
record.setValue({
fieldId: 'custbody_sor_temptest',
value: null
});
}
} catch (e) {
console.log('ERROR', JSON.stringify(e));
}
}
function sendemail() {
var userid = runtime.getCurrentUser().user;
var useremail = runtime.getCurrentUser().email;
email.send({
author: userid,
recipients: useremail,
subject: 'Test',
body: 'my first email',
attachments: null,
relatedRecords: null
});
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged,
saveRecord: sendemail
};
});
答案 0 :(得分:0)
使用开发或沙盒帐户可能会抑制电子邮件,因为没有登录上下文。尝试在生产帐户上工作,然后它应该可以工作。