Search code examples
netsuitesuitescript

nlapiSendEmail not attaching to a custom record


I have a script emailing a custom PDF to an entity. The PDF is generated from a custom record, and I want to be able to see the email from the entity (ok - no problem), and also the custom record mail merge tab (or comms).

Entity is fine, but the custom record is not showing the email:

The code:

var records = new Object();
records['entity'] = venId[each];
records['customrecord_sow'] = sowId;
log('Attach email to records: '+stringify(records));
                
nlapiSendEmail(nlapiGetUser(), recipient, subject, body, null, null, records , newFile,true);

When I view the log, the record variable contains the following:

Attach email to records: { "entity": 11, "customrecord_sow": "264" }

The record internal id is correct, as the the custom record id. But the email does not show in the mail merge on the record.

What have I missed?


Solution

  • For custom records, you have to specify both the custom record type id as well as the custom record id in the records object. So in your case, you would need to do something like this:

    records['recordtype'] = 'customrecord_sow';
    records['record'] = sowId;
    

    in place of records['customrecord_sow'] = sowId;