Inline Editing with SuiteScript

Other topics

Remarks:

The submitFields functionality is a companion feature to the lookupFields functionality.

Performance and Limitations

submitFields performs significantly faster and uses less governance than making the same changes by loading and submitting the full record.

Multiple fields can be updated at once for the same cost as updating a single field. Updating more fields with submitFields does not incur a higher governance cost.

However, you must be aware that only certain fields on each record type are inline-editable, and the performance savings only applies to these inline-editable fields. If you use the submitFields function on any non-inline-editable field, the field will be updated correctly, but behind the scenes, NetSuite will actually load and submit the record, thus taking more time and using more governance. You can determine whether a field is inline-editable by referring to the "nlapiSubmitField" column in the Records Browser.

submitFields functionality is also limited to the body fields of a record. If you need to modify sublist data, you will need to load the record to make your changes, then submit the record.

References:

  • NetSuite Help: "Inline Editing and SuiteScript Overview"
  • NetSuite Help: "Inline Editing Using nlapiSubmitField"
  • NetSuite Help: "Consequences of Using nlapiSubmitField on Non Inline Editable Fields"
  • NetSuite Help: "Field APIs"
  • NetSuite Help: "record.submitFields(options)"

[1.0] Submit a Single Field

/**
 * A SuiteScript 1.0 example of using nlapiSubmitField to update a single field on a related record
 */

// From a Sales Order, get the Customer ID
var customerId = nlapiGetFieldValue("entity");

// Set a comment on the Customer record
nlapiSubmitField("customer", customerId, "comments", "This is a comment added by inline editing with SuiteScript.");

[1.0] Submit Multiple Fields

/**
 * A SuiteScript 1.0 example of using nlapiSubmitField to update multiple fields on a related record
 */

// From a Sales Order, get the Customer ID
var customerId = nlapiGetFieldValue("entity");

// Set a Comment and update the Budget Approved field on the Customer record
nlapiSubmitField("customer", customerId,
    ["comments", "isbudgetapproved"],
    ["The budget has been approved.", "T"]);

[2.0] Submit a Single Field

/**
 * A SuiteScript 2.0 example of using N/record#submitFields to update a single field on a related record
 */

require(["N/record", "N/currentRecord"], function (r, cr) {

    // From a Sales Order, get the Customer ID
    var customerId = cr.get().getValue({"fieldId": "entity"});

    // Set a Comment on the Customer record
    r.submitFields({
        "type": r.Type.CUSTOMER,
        "id": customerId,
        "values": {
            "comments": "This is a comment added by inline editing with SuiteScript."
        }
    });
});

[2.0] Submit Multiple Fields

/**
 * A SuiteScript 2.0 example of using N/record#submitFields to update multiple fields on a related record
 */

require(["N/record", "N/currentRecord"], function (r, cr) {

    // From a Sales Order, get the Customer ID
    var customerId = cr.get().getValue({"fieldId": "entity"});

    // Set a Comment and check the Budget Approved box on the Customer record
    r.submitFields({
        "type": r.Type.CUSTOMER,
        "id": customerId,
        "values": {
            "comments": "The budget has been approved.",
            "isbudgetapproved": true
        }
    });
});

Syntax:

  • nlapiSubmitField(recordType, recordId, fieldId, fieldValue);
  • nlapiSubmitField(recordType, recordId, fieldIds, fieldValues);
  • nlapiSubmitField(recordType, recordId, fieldId, fieldValue, doSourcing);

Parameters:

ParameterDetails
recordTypeString - The internal ID of the type of record being updated
recordIdString or Number - The internal ID of the record being updated
fieldIdsString or String[] - The internal ID(s) of the field(s) being updated
fieldValuesany or any[] - The corresponding values to be set in the given fields
doSourcingBoolean - Whether dependent values should be sourced in upon record submission. Default is false

Contributors

Topic Id: 9082

Example Ids: 28203,28204,28205,28206

This site is not affiliated with any of the contributors.