Create and Save a Contact Record

The following sample shows how to use the N/record module to create and save a contact record.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

Important:

Some of the values in these samples are placeholders. Before using these samples, replace all hard-coded values, such as IDs and file paths, with valid values from your NetSuite account. If you run a script with an invalid value, the system may throw an error.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

          /**
 * @NApiVersion 2.1
 */
require(['N/record'], record => {
    // Create an object to hold name data for the contact
    const nameData = {
        firstname: 'John',
        middlename: 'Doe',
        lastname: 'Smith'
    };

    // Create a contact record
    let objRecord = record.create({
        type: record.Type.CONTACT,
        isDynamic: true
    });

    // Set the values of the subsidiary, firstname, middlename,
    // and lastname properties
    objRecord.setValue({
        fieldId: 'subsidiary',
        value: '1'
    });
    for (let key in nameData) {
        if (nameData.hasOwnProperty(key)) {
            objRecord.setValue({
                fieldId: key,
                value: nameData[key]
            });
        }
    }

    // Save the record
    let recordId = objRecord.save({
        enableSourcing: false,
        ignoreMandatoryFields: false
    });
}); 

        

General Notices