Members
-
<private> _changing
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> _pending
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> _previousAttributes
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> attributes
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> changed
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> cid
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> cidPrefix
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> collection
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> defaults
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> id
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<protected> idAttribute
-
Description
Lets you use an arbitrary attribute (instead of the default
id
attribute) to store a model's identifier. The default value of idAttribute is 'internalid', which is the unique identifier of most records in NetSuite. -
<private> operationIds
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
-
<private> validation
-
Description
An internal property. Do not override or use this property. If you override this property, your SuiteCommerce website might not work as expected.
Methods
-
<private> _validate()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> addOperationId()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> changedAttributes()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> clear()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> clone()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> deepCopy()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
destroy() → {false|Deferred}
-
Description
Destroys (deletes) the model on the server.
Returns
-
<private> escape()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
fetch() → {Deferred}
-
Description
Gets model data from the server.
var product = new ProductModel(); product.fetch().done(function() { // ... });
Returns
-
get( attributeName ) → {*}
-
Description
Allows you to get the value of a model attribute.
var product = new ProductModel(); var productPrice = product.get("price");
Parameters
Name Type Description attributeName
string The name of the attribute.
Returns
-
<private> getLatestOperationIds()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> getOperationIds()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
getValidationErrors() → {null|Object}
-
Description
Gets the errors, if any, after validation of the model. Errors are returned in an object in which model attributes are the keys and errors are the values of those keys.
You must create the validation rules by overriding the getValidationRules() method.
You can call this method after setting an attribute on the model with set(). Whenever you set attributes on the model, the attributes are validated according to the validation rules in
getValidationRules()
.var review = new ReviewModel(); review.set('reviewername').done(function() { var errors = review.getValidationErrors(); if (errors !== null) { // Do something with the errors // ... } });
Returns
-
<protected> getValidationRules() → {Object}
-
Description
Lets you define validation rules for the model. You define validation rules by returning an object that contains the rules. Each key in the object is a field name; the corresponding value is an array of validation rules. A rule is a function (anonymous or named) that accepts the field value and its name. The function should return an error message as a string if validation fails. Otherwise, it must return a falsy value ('', undefined, 0, and so on).
Validation rules are evaluated whenever set() or save() is called on the model.
The following example shows validation rules for two fields:
recipient
andrecipientphone
. A single rule is defined forrecipient
, whereas two rules are defined forrecipientphone
.MySCModel.prototype.getValidationRules = function() { return { recipient: [ function(value, name) { if (typeof value === 'undefined' || value.length === 0) { return 'You must enter a recipient name.'; } } ], recipientphone: [ function(value, name) { if (typeof value === 'undefined' || value.length === 0) { return 'You must enter a recipient phone number.'; } }, function(value, name) { if (value.length >= 12) { return 'Phone number must be less than 12 digits.'; } } ] } }
If the model does not require validation, you don't need to implement
getValidationRules()
. Alternatively, you can simply return an empty string.MySCModel.prototype.getValidationRules = function() { return ''; }
Returns
-
has( attributeName ) → {Boolean}
-
Description
Returns
true
if the attribute has a value (it is not null or undefined).var review = new ReviewModel(); if (review.has('reviewername')) { // ... }
Parameters
Name Type Description attributeName
The name of the attribute.
Returns
-
hasChanged( attributeName ) → {Boolean}
-
Description
Returns
true
if an attribute has changed since it was last set (with set()).var review = new ReviewModel(); if (review.hasChanged('rating')) { // ... }
Parameters
Name Type Description attributeName
The name of the attribute.
Returns
-
<private> initialize()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
isNew() → {Boolean}
-
Description
Returns
true
if the model is new (has never been saved to the server).Returns
-
<private> isValid()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> preinitialize()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> previous()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> previousAttributes()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
save()
-
Description
Saves the model to the server. Before data is sent to the server, it validates the model attributes with getValidationRules(). If there are no errors, it saves to the server; otherwise, it returns false if the validation fails. Always validates regardless of whether attributes were passed.
var review = new ReviewModel(); review.set('reviewername', 'J. Smith'); result = review.save(); // result can be a promise or false
-
set( attributeName, value )
-
Description
Sets an attribute of the model. When an attribute is set, it triggers validation for the model as defined in getValidationRules(). You can use getValidationErrors() to check for validation errors.
Parameters
Name Type Description attributeName
string The name of the attribute.
value
* The value of the attribute.
-
<private> sync()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
<private> unset()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.
-
url() → {String}
-
Description
A property that returns the URL of the model with an additional parameter called
internalid
. The URL includes the URL root, as specified by urlRoot(), and the model ID as the value ofinternalid
.url
is called by default when you save or fetch from the server. The value ofurl
must be a function that returns a string.Returns
-
<protected> urlRoot() → {String}
-
Description
Specifies the root URL of models. By default, the value is an empty string, so you must override
urlRoot
if you want to be able to save or fetch data from the server. The value ofurlRoot
must be a function that returns a string and should point to the appropriate resource on the server for the model.function MySCModel() { SCModel.call(this); this.urlRoot = function() { return Utils.getAbsoluteUrl( getExtensionAssetsPath("services/MainModule.Service.ss") ) } }
Returns
-
<private> validate()
-
Description
An internal method. Do not override this method. If you override this method, your SuiteCommerce website might not work as expected.