Importance of the defaultValue in the record.create

When you create records of certain types, you can use the defaultValues parameter to provide default values for fields in the new record. For some record types, some default values are required. For example, when you create a script deployment record, you must provide the internal ID of an existing script in your account (to associate with the script deployment record):

var scriptDeployment = record.create({
    type: record.Type.SCRIPT_DEPLOYMENT,
    defaultValues: {
        script: 205       // Internal id of existing script record
    }
});

Other use cases:

When creating a non-inventory sales item through SuiteScript, an error will occur if a subtype is not specified. The subtype should be set to “Sales” by default. Without this, the system assumes the item being created is a purchase item, and during record.save, it will run mandatory field validations accordingly and will throw the following error.

{
   type: "error.SuiteScriptError",
   name: "USER_ERROR",
   message: "You must specify expense and income accounts for this item.",
   id: "",
   stack: [
      "Errorn    at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)n    at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)n    at Object.post (/SuiteScripts/JobinAndJismi/RBXIN-543 NS to NS Integration/Scripts/Restlet/jj_rl_itemsync_rbxin579.js:213:40)"   ],   cause: {
      type: "internal error",
      code: "USER_ERROR",
      details: "You must specify expense and income accounts for this item.",
      userEvent: null,
      stackTrace: [
         "Errorn    at RecordInvoker.save (suitescript/resources/javascript/record/serverRecordService.js:371:13)n    at NetSuiteObject.thenableFunction() (suitescript/resources/javascript/record/proxy.js:115:24)n    at Object.post (/SuiteScripts/JobinAndJismi/RBXIN-543 NS to NS Integration/Scripts/Restlet/jj_rl_itemsync_rbxin579.js:213:40)"
      ],
      notifyOff: false
   },
   notifyOff: false,
   userFacing: true
}

Note:

All the field values in the record can’t be set as deafultValue. NetSuite provides a list of possible default value fields for each record. Make sure that you check for supported default values as you create records. For a list of available record default values, see N/record Default Values.

Leave a comment

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