Methods to attach emails to NetSuite records without sending

Method 1: Adding Internal Messages Using  N/message Module

This method allows you to create messages that can be associated with records.

/**

* @NApiVersion 2.x

* @NScriptType UserEventScript

*/

define([‘N/message’, ‘N/record’], (message, record) => {

   const addInternalMessage = (recordId) => {

       // Create a new message

      let messageRecord = record.create({

        type: ‘message’,

        isDynamic: true

      });

      messageRecord.setValue({

        fieldId: ‘author’,

        value: authorId

      });

      messageRecord.setValue({

        fieldId: ‘recipient’,

        value: recipientId

      });

      messageRecord.setValue({

        fieldId: ‘subject’,

        value: subjectText

      });

      messageRecord.setValue({

        fieldId: ‘message’,

        value: messageContentText

      });

      messageRecord.setValue({

        fieldId: ‘transaction’,

        value: transactionId

      });

      let messageId = messageRecord.save();

        

});

Method 2: Sending Internal Emails Using N/email Module(internal only option)

This method allows you to send emails internally without sending them to external recipients.

/**

 * @NApiVersion 2.x

 * @NScriptType UserEventScript

 */

define([‘N/email’, ‘N/record’], (email, record) => {

    const addInternalEmail = (recordId) => {

        // Prepare email details

        const emailDetails = {

            author: -5, // Use -5 for the current user

            recipients: [‘internal@example.com’], // Use an internal email address

            subject: ‘Internal Email Subject’,

            body: ‘This is the content of the internal email.’,

            isInternalOnly: true // Ensures the email is not sent externally

relatedRecords: { // Add the transaction here

                transactionId: transactionId,

entityId: entityIdValue

              },

        };

        // Send the email (internally)

        email.send(emailDetails);

    };

});

Leave a comment

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