Using Objects When Calling Standard Methods

Many SuiteScript 2.x methods need you to provide one or more pieces of information, all wrapped up in a single object. This object has one or more properties, which can be required or optional. You need to set a value for each required property, as well as any optional ones you use in your script.

When you set a value on a record, you use the Record.setValue(options) method. With this method, you need to provide two things: the ID of the field and the value you want to set. To do that, you create an object with a fieldId property and a value property, then pass that object to the method. For example:

          var myObject =  {
    fieldId: 'Hello!',
    value: 'Hello, World!'
}; 

myRecord.setValue(myObject); 

        

Another way to pass an object is to define it right inside the method call. For example:

          myRecord.setValue({
    fieldId: 'Hello!',
    value: 'Hello, World!'
}); 

        

In the documentation for standard SuiteScript 2.x methods, each method's argument is usually called options. But in your script, you can name the object whatever you want. For an example, see SuiteScript 2.x User Event Script Tutorial.

Note:

In SuiteScript 2.x, you can't add inline comments inside an object. You might not see a specific error, but your script won't work right if you include comments inside an object.

Related Topics

General Notices