Note: Nintex Apps data centers are located in West US and Australia (AUS). In-region processing of Nintex Apps data is only available in these regions.
All code samples below refer to the skuid object.
In the v2 API, this object is not directly accessible when working within a browser console—or when referring to another Nintex Apps page runtime.
If you are experiencing issues, use the skuid.runtime API to target the appropriate page context.
skuid.model.Model
All models on a Nintex Apps page are constructed by Nintex Apps as skuid.model.Model objects and will have the properties listed below.
To see these properties in action, use the skuid.model.getModelsByName() function at runtime.
Properties
Property | Type | Required | Description |
---|---|---|---|
skuid.model.Model.canRetrieveMoreRows | boolean | No |
Indicates whether there are more rows in the dataset beyond the limit requested by the user. |
skuid.model.Model.changes | object | No |
Represents changes to the model which have not yet been committed to the database via save() . A simple object mapping of row Ids to rows that have changed. Each row is a simple map of field names to values that have changed. cancel() empties changes. If no changes have been made since the last save() or cancel() , this will be an empty object. |
skuid.model.Model.createRowIfNoneFound | boolean | No |
Indicates if a row will be created when no records are returned by the model's query or if the model is set not to query for records on page load, as defined in the Page Designer. |
skuid.model.Model.conditionLogic | string | No |
Defines the logic to use when combining the Model conditions. If no conditionLogic is specified, Nintex Apps will combine all conditions using AND logic, e.g. 1 AND 2 AND ... Example: "(1 AND 2) OR (3 AND 4)" |
skuid.model.Model.conditions | Unknown Type | No |
Model Condition Metadata Object[] An array of Condition Metadata Objects associated with the model. |
skuid.model.Model.data | object[] | No |
An array of rows within the model. To retrieve this array directly, use getRows() . Each element within the array is a simple map of field names to values. For example, a row within a model with three fields, two from the object, "Name" and "CustomField__c", and one from a lookup relationship, "skuid__AttachmentId__c" from the sObject "skuid__Image__c" via the relationship "Image__r", would be represented as: Copy
Note: It is typically not best practice to use this object to work with rows or their data. , use the getter APIs getFirstRow() or getRowById() when attempting to work with a row using custom code. |
skuid.model.Model.dataMap | object | No |
Read-only. Use getRowById() to request a particular row by its ID and createRow() or adoptRows() to add new data to a model. For the data array, see the documentation for the Model Metadata Object Note: Direct use of this property is not recommended. |
skuid.model.Model.fields | Unknown Type | No |
Model Field Metadata Object [] An array of Field Metadata Objects, one for each field explicitly defined in the model. For example, a model with three fields, two from the object, "Name" and "CustomField__c", and one from a lookup relationship, "skuid__AttachmentId__c" from the sObject "skuid__Image__c" via the relationship "Image__r", would have three elements in this array. Note: Unlike the data and dataMap properties, an object's ID field is not included unless explicitly included in the model. Note: Fields are not guaranteed to be in any particular order. |
skuid.model.Model.fieldsMap | object | No |
Read-only. A simple object map of field names to Model Field Metadata Objects. Note: It is recommended to use getField() to request field metadata for a particular field by its name, rather than directly accessing fieldsMap . You can access the Field Metadata either by standard hierarchical objects (i.e. fieldsMap.Object__r.FieldName ) or by using the fully qualified name via array syntax (i.e. fieldsMap['Object__r.FieldName'] ). For example, a Model with three fields, two from the object, "Name" and "CustomField__c", and one from a lookup relationship, "skuid__AttachmentId__c" from the sObject "skuid__Image__c" via the relationship "Image__r", would be represented as: Copy
For the field array, see the documentation for the Model Field Metadata Object. Note: Unlike the data and dataMap properties, fieldsMap does not include ID fields unless they are explicitly included in the model. |
skuid.model.Model.groupByFields | Unknown Type | No |
Model Field Metadata Object [] An array of Field Metadata Objects used to group an aggregate model. For basic models, this property is null. |
skuid.model.Model.groupByMethod | string | No |
A description of the grouping method. One of:
|
skuid.model.Model.hasChanged | boolean | No |
Read-only. Indicates if the model contains changes that have not been committed to the database. |
skuid.model.Model.id | string | No |
The unique identifier assigned to the model in the Nintex Apps Page Designer. |
skuid.model.Model.orderByClause | string | No |
The Fields to Order Records By Clause defined from the Page Designer. Defines the ORDER BY clause in the model's generated SOQL query. |
skuid.model.Model.originals | object | No |
A corollary to changes . Contains the original value for each field value change which has not yet been committed to the database. A simple object mapping of row Ids to rows that have changed. Each row is a simple map of field names to the original values before they were changed. |
skuid.model.Model.readonly | boolean | No |
Indicates whether the model should be treated as read-only. |
skuid.model.Model.recordsLimit | number | No |
An integer value indicating the maximum number of rows to fetch from the database, as defined in the Page Designer. If the value given was less than 0, then the default is 1. If no value was given, then value will be null (and no limit will be placed on the query). Note: When attempting to query for more data, updating the recordsLimit property directly is not recommended and may result in inaccurate data. , consider using the batchSize property of loadAllRemainingRecords() . |
skuid.model.Model.registeredFields | object | No |
Read-only. A simple object map of Nintex Apps Unique Ids to Field objects registered with the model. |
skuid.model.Model.soql | string | No |
The complete generated SOQL statement used to populate the model's data, including requested fields and conditions, as well as any GROUP BY, ORDER BY and LIMIT clauses. |
skuid.model.Model.type | string | No |
The Model Type as defined in the Page Builder. One of:
|
Prototype Functions
Every Nintex Apps model created will be able to perform the following functions.
skuid.model.Model.abandonRow(row)
Removes a row from a model without requesting that it be deleted from the database.
When this function is called, the row will be removed from the data array, the dataMap , and the changes and originals maps. The item associated with the row will be removed from the registeredItems array. Any fields associated with the row will be removed from the registeredFields array. Any lists that contained the item will be notified that the item was deleted (via the handleRowDeletion function). Finally, the hasChanged property will be reassessed to determine whether the model still has changes.
Arguments: | Returns: |
---|---|
|
The abandoned row object. |
Note: Attempting to abandon a row from another model or the clone of a row is unsupported and may cause unexpected behavior.
skuid.model.Model.abandonRows(rows)
Removes an array of rows from a model without requesting that that the rows be deleted from the database. Bulk version of abandonRow() . It is highly recommended to use abandonRows() rather than abandonRow() if you are removing more than one row from a model.
When this function is called, the rows will be removed from the data array, the dataMap , and the changes and originals maps. The items associated with the rows will be removed from the registeredItems array. Any fields associated with the rows will be removed from the registeredFields array. Any lists that contained the items will be notified that the items were deleted (via the handleRowDeletion function). Finally, the hasChanged property will be reassessed to determine whether the model still has changes.
Arguments: | Returns: |
---|---|
|
The array of abandoned row objects (if provided) or undefined if no rows or an empty array of rows was provided. |
Note: Attempting to abandon rows from another model or the clones of rows is unsupported and may cause unexpected behavior.
skuid.model.Model.abandonAllRows()
Removes all rows from the Model, and cancels all changes. Publishes the 'models.loaded' event for the Model. Identical to emptyData().
skuid.model.Model.activateCondition(condition,affectPersonalization)
Activates a condition so that it will be applied to future queries on this model.
Use getConditionByName() to retrieve a condition.
To immediately apply the condition after activating it, call updateData() .
Arguments: |
---|
|
Note: Use activateCondition() for "toggle" style conditions. If the condition uses a value (such as filtering by Product Family on the Product2 sObject), then use setCondition() .
skuid.model.Model.adoptRows(rows[,options])
Used for incorporating "external" rows into a Nintex Apps model, e.g. rows coming from an external connection or web service, rows created/modified in Salesforce and then returned to Nintex Apps via a non- Nintex Apps Apex controller method, or rows manually created in JavaScript through a non- Nintex Apps API method. Adopted rows will be matched against existing rows by their ID field/property.
If a matching existing row is found, it will be merged with the matching incoming row object, with the incoming row object's properties taking precedence. If no corresponding existing row is found, then the incoming row will be prepended / appended to the Model's data array. If an incoming row does not contain an Id, then Nintex Apps will generate a unique ID for the row.
Unless the doAppend option is set to true, model rows will be prepended to the model data in order.
Note: In versions of Nintex Apps below v11, rows would be prepended in reverse order.
For example:
-
A model contains
- [Row A]
- [Row B]
-
adoptRows() is used to adopt the following:
- [Row 1]
- [Row 2]
- [Row 3]
-
The model's rows will now be:
- [Row 1]
- [Row 2]
- [Row 3]
- [Row A]
- [Row B]
If doAppend is true, the rows will be:
- [Row A]
- [Row B]
- [Row 1]
- [Row 2]
- [Row 3]
Arguments: | Returns: | Return type: |
---|---|---|
|
The row objects that were adopted into the model, post-adoption. |
object[] |
skuid.model.Model.cancel()
Reverts all changes made to this model since it was last saved or updated, using values stored in originals and emptying changes. Unsaved newly-created rows that are flagged for deletion are immediately removed from data.
Returns: | Return type: |
---|---|
Returns this model to enable function chaining. | skuid.model.Model |
skuid.model.Model.createRow(options)
Creates a new row and attaches it to this model.
Arguments: | Returns: | Return type: |
---|---|---|
|
The newly created row object. |
object |
skuid.model.Model.deactivateCondition(condition,affectPersonalization)
Deactivates the given skuid.model.Condition() so that it will not be applied to future queries on this model.
Use getConditionByName() to retrieve a condition.
Arguments: |
---|
|
skuid.model.Model.deleteRow(row)
Marks the given row for deletion. The row will not be deleted from the database until the save() method is called.
To un-mark a row for deletion, see undeleteRow() .
Arguments: |
---|
|
Note: The row object only requires an ID field. If you have a row ID and want to mark it for deletion, you can call deleteRow( { Id: <row Id> } );
skuid.model.Model.emptyData()
Removes all rows from the model, and cancels all changes. Publishes the 'models.loaded' event for the model. Identical behavior to abandonAllRows() .
skuid.model.Model.exportData(options)
Exports either all or a subset of the rows in the model to a CSV file. The CSV file will be automatically downloaded to the user's device when this method is called.
Arguments: |
---|
|
For example:
var model = skuid.model.getModel('LeadData');
model.exportData({
fileName: 'UnconvertedLeads',
fields: [
model.getField('FirstName'),
model.getField('LastName'),
model.getField('Company'),
model.getField('Email')
],
doNotAppendRowIdColumn: true,
additionalConditions: [
{
field: "IsConverted",
value: false,
operator: '=',
encloseValueInQuotes: false
}
]
});
var moreCode = null;
skuid.model.Model.evaluateFormulaField(row,field)
Evaluates a single formula field on a single Model Row. Components will not display evaluated values until re-rendered.
Arguments: | Returns: | Return type: |
---|---|---|
|
The result of the formula evaluation |
String|Number |
skuid.model.Model.evaluateFormulaFields([options])
Evaluates formula fields on the Model—either all rows or those provided in the updatedRows parameter. In contrast to evaluateFormulaField , contains additional logic that will then notify UI components to update, pending the preventTrackChanges parameter.
Arguments: | Returns: | Return type: |
---|---|---|
|
The Model object, used for chaining |
Object |
skuid.model.Model.getConditionByName(conditionName,searchSubconditions)
Searches this Model for a Condition whose name property equals conditionName.
Arguments: | Returns: | Return type: |
---|---|---|
|
The Condition associated with the given name, or false if the Condition name was not recognized. |
skuid.model.Model.getField(fieldName)
Returns metadata about a field in this model.
Arguments: | Returns: | Return type: |
---|---|---|
|
Returns metadata about a field, or false if the field name was not recognized. |
skuid.model.Model.getFieldValue(row,field,noEscape)
Returns the value for a particular field in a row from this model or returns undefined if the requested field is not found in the model.
Use model methods that return rows such as getFirstRow( ) to retrieve an instance of a row.
Arguments: | Returns: | Return type: |
---|---|---|
|
The value of the field for the given row in this Model, or undefined if there is no value for the field on the row. |
The value of the field, which may be a string, number, object, array, etc. |
EXAMPLE:
The benefit of using this method is that field can be specified as a string in relational syntax, e.g. 'Account.Parent.Owner.Name', and Nintex Apps will automatically traverse the object hierarchy in that row. For example, if your data row looks like this:
{
Account: {
Parent: {
Owner: {
Name: "George Bailey",
Id: "005000000000123AAA"
},
OwnerId: "005000000000123AAA",
Name : "The Parent Account",
Id: "001000000000011AAA"
},
ParentId: "001000000000011AAA",
Name: "Main Account"
}
}
then model.getFieldValue( row, 'Account.Parent.Owner.Name' ) will return 'George Bailey'.
skuid.model.Model.getFirstRow()
Returns: | Return type: |
---|---|
The first row in this model's data array | object |
skuid.model.Model.getRowById(id)
Returns the row in this model identified by the given ID.
Arguments: | Returns: | Return type: |
---|---|---|
|
A row object |
object |
skuid.model.Model.getRows(dataConditions,context)
Returns all rows in this Model's data array. This is the officially supported way to retrieve all rows in a Model.
Arguments: | Returns: | Return type: |
---|---|---|
|
An array all row objects in this Model. |
array of row objects |
skuid.model.Model.isRowChanged(row)
Checks whether there are any unsaved changes associated with a particular row in a Model.
Arguments: | Returns: | Return type: |
---|---|---|
|
Returns true if the row has any unsaved changes, otherwise returns false. |
boolean |
skuid.model.Model.isRowMarkedForDeletion(row)
Checks whether a Model row has been marked for deletion.
Arguments: | Returns: | Return type: |
---|---|---|
|
Returns true if the row has been marked for deletion, otherwise returns false. |
boolean |
skuid.model.Model.isRowNew(row)
Checks whether a Model row has not yet been committed to the Model's associated data service.
Arguments: | Returns: | Return type: |
---|---|---|
|
Returns true if the row has not yet been committed, otherwise returns false. |
boolean |
skuid.model.Model.isRowUnsavedClone(row)
Checks whether an unsaved / new Model row was originally cloned from a preexisting, saved record via Nintex Apps's model cloning functionality.
Arguments: | Returns: | Return type: |
---|---|---|
|
Returns true if the row is new / unsaved and was originally cloned from a preexisting, saved record. Otherwise, returns false. |
boolean |
skuid.model.Model.loadAllRemainingRecords(options)
If the Model had a LIMIT clause applied to it and there are records in the database which were not retrieved in the prior/initial query, then loadAllRemainingRecords will call loadNextOffsetPage until the Model indicates that there are no more records available for retrieval.
Arguments: |
---|
|
EXAMPLE
Scenario: Your Model "Accounts" has a limit of 50, and there are a total of 271 rows in the database that meet the Model's Conditions. Running the following:
skuid.$.blockUI({ message: 'Loading all available Accounts...' });
skuid.$M("Accounts").loadAllRemainingRecords({
stepCallback: function(offsetStart,offsetEnd) {
skuid.$.blockUI({ message: 'Loading Accounts ' + offsetStart + ' to ' + offsetEnd + '...' });
},
finishCallback: function(totalRecordsRetrieved) {
skuid.$.blockUI({ message: 'Finished loading all ' + totalRecordsRetrieved + ' Accounts!', timeout: 2000 });
}
});
Will produce the following sequence of Block UI messages:
- "Loading all available Accounts..."
- "Loading Accounts 51 to 100..."
- "Loading Accounts 101 to 150..."
- "Loading Accounts 151 to 200..."
- "Loading Accounts 201 to 250..."
- Loading Accounts 251 to 300..."
- "Finished loading all 271 Accounts!"
skuid.model.Model.loadNextOffsetPage(callback)
If the Model had a LIMIT clause applied to it and there are rows in the database which were not fetched in a prior query then loadNextOffsetPage fetches the next "set" of data based on the LIMIT clause size.
Arguments: |
---|
|
skuid.model.Model.removeRowById(id)
Calls abandonRow( ) for the row in the Model with the given ID.
Arguments: | Returns: | Return type: |
---|---|---|
|
The abandoned row object. |
object |
skuid.model.Model.resetCondition(condition)
Will reset the value of a model's condition to the default value of that condition.
Use getConditionByName() to retrieve a Condition.
To immediately apply the Condition after activating it, call updateData() .
Arguments: |
---|
|
skuid.model.Model.save(options)
Sends all changes to this model to the server.
Arguments: | Returns: | Return type: |
---|---|---|
|
A Promise object which is resolved upon completion of the save operation. Note: Check the totalsuccess property on the result object to confirm that the save operation was successful. The Promise will be rejected if the network request failed. |
skuid.model.Model.setCondition(condition,value,affectPersonalization)
Sets the value of a Condition on the Model and activates the Condition so that it will be applied to future queries on this Model.
Use getConditionByName() to retrieve a Condition.
To immediately apply the Condition after activating it, call updateData( ).
Arguments: |
---|
|
Note: Use setCondition( ) for Conditions that filter on a specific value, such as filtering by Product Family on the Product2 sObject. For "toggle" style Conditions, use activateCondition( ).
skuid.model.Model.undeleteRow(row)
Unmarks the given row for deletion. This function has no effect on rows that have already been deleted on the server.
Arguments: |
---|
|
Note: The row object only requires an ID field. If you have a row ID and want to un-mark it for deletion, you can call undeleteRow( { Id: <row Id> } );
To recover a record deleted on the server, see Salesforce's Recycle Bin documentation
skuid.model.Model.updateData(callback)
Requests an update (or "refresh") for this Model from the server.
This function will throw a JavaScript error if there are unsaved changes in the Model. To cancel unsaved changes, see cancel( ).
Arguments: | Returns: | Return type: |
---|---|---|
|
The Promise object is resolved upon completion of the update operation. |
skuid.model.Model.updateRow(row,updates[,options])
Updates the value of the given row and fields, then notifies all registered UI elements that changes took place.
Note: If updating several rows within a loop, it is much more efficient to use the updateRows( ) function.
Changes made will not be sent to the server until the save( ) method is called.
Arguments: |
---|
|
{
Name: 'New Name',
CustomField__c: 'New Value'
}
Arguments: | Returns: | Return type: |
---|---|---|
|
The updated row object. |
object |
EXAMPLE:
Given a row Id, update the row's Name and Custom Field values:
updateRow(
{ Id: '<row Id>' },
{
Name: 'New Name',
CustomField__c: 'New Value'
}
);
skuid.model.Model.updateRows(updates[,options])
Updates the value of the given rows and fields, then notifies all registered UI elements that changes took place.
Changes made will not be sent to the server until the save( ) method is called.
Arguments: | Returns: | Return type: |
---|---|---|
|
The updated row objects. |
object |
EXAMPLE:
Update the Name and Custom Field values of all rows loaded into myModel:
var rowsToUpdate = {};
$.each( myModel.getRows(), function(){
rowsToUpdate[this.Id] = { Name: 'New Name 1', CustomField__c: 'New Value 1' };
});
myModel.updateRows( rowsToUpdate );
skuid.model.Model.validateRequiredFields()
Calls validateRequiredFields() on each List registered on the Model. For each required field defined on each List, the List will validate each of its Rendered Items to ensure that the row has values for each required field. If any required fields do not have values, a Message object is created. This method returns a list of all Message objects returned by any registered List on the Model.
Returns: | Return type: |
---|---|
Message object properties:
|
Array of Message objects |
Example: Accessing Models, Rows, and Updating Data
It is common to use skuid.model APIs to obtain information about a specific model, and then use skuid.model.Model APIs to interact with that specific model's data.
For example, let's create a new contact record:
// The most common uses of skuid.model APIs are
// to retrieve a list of page models
skuid.model.map()
// and to obtain a reference to a specific model
var contactModel = skuid.$M('ContactModel');
var accountModel = skuid.$M('AccountModel');
// With a references set to a skuid.model.Model,
// it's easier to use skuid.model.Model APIs to access
// the first rows of those models, which are probably
// existing rows from a database.
var firstAccount = accountModel.getFirstRow();
var firstContact = contactModel.getFirstRow();
// Now to create a new contact in our Contact model,
// passing in additional conditions so that new contact
// has default values. If there are other existing conditions
// or default field values, those will be applied to the new row as well.
var georgeBailey = contactModel.createRow({
additionalConditions: [
{ field: 'FirstName', value: 'George'},
{ field: 'LastName', value: 'Bailey'},
{ field: 'Birthdate', value: '1942-03-24'}
], doAppend: true
});
// First create a shortcut to the provided jQuery
var $ = skuid.$
// Next, change each contact in the Contact model
// to be associated the first account in the Account model.
$.each(contactModel.data,function(i,row){
contactModel.updateRow(row,{
AccountId: firstAccount.Id,
Account: firstAccount
});
});
// Save all changes in our Contact model
contactModel.save({callback: function(result){
if (result.totalsuccess) {
// Get the 15-digit ID of our newly-saved George Bailey Contact,
// which will have had its ID and other fields updated after save
console.log(georgeBailey.Id15);
// Show the entire George Bailey Contact record
console.log(georgeBailey);
} else {
console.log('The save failed.');
console.log(result.insertResults);
console.log(result.updateResults);
console.log(result.deleteResults);
}
}});
If this snippet takes places within a set of actions in the Action Framework, be sure to return the result of the model save function. Otherwise the Action Framework will continue before the save request completes.
Replace the lines 35-48 with this code:
return contactModel.save({callback: function(result){
if (result.totalsuccess) {
// Success logic
} else {
// Failure logic
}
}});
Your set of actions continue regardless of whether the save fails or succeeds. This logic simply tells Nintex Apps to wait until the save request is complete—regardless of success.
If you require more advanced logic based on the save's success, you need to adjust your code accordingly, potentially using promises.