2017-07-03 91 views
1

我对NetSuite脚本相当陌生,并且存在以下问题。NetSuite SuiteScript 1.0电子邮件附件

我想从SuiteScript 1.0发送电子邮件。脚本链接到销售订单的AFTER SUBMIT功能。

我的代码:

function OnAfterSubmit(record) { 
    var fromId = -5; //Authors' Internal ID 
    var sbj = 'subject'; 
    var msg = ''; 

    //load File from netSuite Document Repository with ID of 123 
    var orderid = nlapiGetRecordId(); 
    var search = nlapiSearchRecord('salesorder', orderid); 
    var fileObj = nlapiLoadRecord(search.getRecordType(), search.getId()); 
    //var detail = getOrderDetail(fileObj); 
    //Single Attachment - Attach File ID 123 
    //nlapiSendEmail(fromId, '[email protected]', sbj, msg, null, null, null, fileObj); 

    //multiple Attachments 
    //build Array of file objects 
    var attach = [fileObj]; 
    //pass attach array as attachment parameter 
    nlapiSendEmail(fromId, '[email protected]', sbj, msg, null, null, null, attach); 
} 

我试图发送已经由用户创建的记录,通过电子邮件。

记录参数似乎不是我所期望的。我收到的错误说“无效搜索”。当我使用record.id时,错误简单地说“id”。我也试过record.internalId

+1

你面临什么问题?请提及,以及 –

+0

记录参数似乎不是我所期望的。我收到的错误说“无效搜索”。当我使用“record.id”时,错误简单地说“id”。我也尝试过“record.internalId”。 – Charl

回答

0
function OnAfterSubmit(type) { 

    var fromId = -5; //Authors' Internal ID 
    var toEmail = '[email protected]'; 
    var sbj = 'subject'; 
    var msg = ''; 

    var newRecord = nlapiGetNewRecord(); 
    var recordAsJSON = JSON.stringify(newRecord); 
    var fileObj = nlapiCreateFile('salesorder.json', 'JSON', recordAsJSON); 

    nlapiSendEmail(fromId, toEmail, sbj, msg, null, null, null, fileObj); 

} 
+0

通过Web服务访问NetSuite时,记录采用XML格式。我可以将该记录作为XML文件从脚本中导出吗? – Charl