1
votes

I am fairly new to NetSuite scripting and have the following issue.

I am trying to send an email from SuiteScript 1.0. The Script is linked to the AFTER SUBMIT function of Sales Orders.

My code:

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);
}

I am trying to send the record that has been created by the user, via email.

The record parameter doesn't seem to be what I expect. The error I receive says "invalid search". When I used record.id, the error simply said "id". I also tried record.internalId.

1
What issues are you facing ? Please mention that as wellPrabodh M
The record parameter doesn't seem to be what I expect. The error I receive says "invalid search". When I used "record.id", the error simply said "id". I also tried "record.internalId".Charl

1 Answers

0
votes
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);

}