I'm currently working on a NetSuite project that requires programmatically attaching notes to Sales Orders. I thought I'd share some of the code that I wrote in support of the project.
Attaching Notes to Transactions
To attach a note to a transaction using SuiteScript, you simply create a note record, and specify the internal ID of the transaction.
Here's a snippet of code that shows how to do this.
var note = record.create( { type: record.Type.NOTE } );
note.setValue( { fieldId: 'title', value: 'Test Note Title' } );
note.setValue( { fieldId: 'notetype', value: 7 } );
note.setValue( { fieldId: 'direction', value: 1 } );
note.setValue( { fieldId: 'note', value: 'Test Note Content' } );
note.setValue( { fieldId: 'transaction', value: 999999 } );
note.save();
The "notetype" field is used to specify the type of note to be created, and the field's supported values are based on the "Note Type" CRM List. You can find a list of the types that are supported in your NetSuite instance by navigating to: Setup > Sales > CRM Lists, and filter the list by selecting "Note Type" as the Type. In most of my clients' instances, "Note" is ID 7.
You can also get an instance's supported note types by querying the NoteType table.
SELECT ID, Name, Description FROM NoteType
The "direction" field is used to indicate if the note is "Incoming" or "Outgoing." For example, if the note originated from outside your organization, the direction would be "Incoming." If the note originated in your organization, and is being sent to someone outside of your organization, you'd set the direction to "Outgoing." When setting the field, use 1 for Incoming, and 2 for Outgoing.
Attaching Notes to Custom Records
Attaching notes to custom records can be a little tricky. For information on how you can do it, check out this blog post by Chidi Okwudire.
Retrieving Notes That Are Attached to a Transaction
To get a list of the notes that are attached to a transaction, you can query the TransactionNote table. Here's a sample query.
SELECT TO_CHAR( TransactionNote.NoteDate, 'YYYY-MM-DD @ HH12:MI PM' ) AS NoteDate, ( Author.FirstName || ' ' || Author.LastName ) AS Author, BUILTIN.DF( TransactionNote.Direction ) AS Direction, TransactionNote.Title, TransactionNote.Note FROM TransactionNote INNER JOIN Employee AS Author ON ( Author.ID = TransactionNote.Author ) WHERE ( Transaction = 999999 ) AND ( NoteType = 7 ) ORDER BY TransactionNote.NoteDate DESC
In this example, I'm joining to the Employee table to get information about the author of the note. Note that I'm using the BUILTIN.DF function on the Direction column to get the text value of the note's direction.