Attach email data to a record without sending an email

Emails attached to the records can be seen under the communication subtab. We can add a new email entry here by using the ‘N/message’ record without actually sending any email. Message records can be edited only during the create operation. After they are created and submitted, existing message records cannot be edited. Existing message records can be copied and deleted. Only beforeLoad and afterSubmit user event scripts will execute on the Message record type when a message is created by an inbound email case capture.

This is useful when you have to add an email captured external source into NetSuite. Refer the code sample:

require(['N/record'], function(record) {
        function makeMessage(){
                var messageRec = record.create ({
                        type: record.Type.MESSAGE,
                        isDynamic: true
                });

                messageRec.setValue({
                        fieldId: 'subject',
                        value: 'Test Message'
                });

                messageRec.setValue({
                        fieldId: 'author',
                        value: 15 //internal id of author name
                });

                messageRec.setValue({
                        fieldId: 'authoremail',
                        value: 'name@example.com'
                });

                messageRec.setValue({
                        fieldId: 'recipient',
                        value: 164 //internal ID of recipient
                });

                messageRec.setValue({
                        fieldId: 'recipientemail',
                        value: 'name@example.com'
                });

                messageRec.setValue({
                        fieldId: 'cc',
                        value: 'name@example1.com, name@example2.com'

                        messageRec.setValue({
                                fieldId: 'bcc',
                                value: 'name@example3.com'
                        });

                        messageRec.setValue({
                                fieldId: 'message',
                                value: 'test message'
                        });

                        var custMessage = messageRec.save();

                        log.debug({title: 'message', details: custMessage
                        });
                }
                makeMessage();
        });
});

Leave a comment

Your email address will not be published. Required fields are marked *