-
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.utils
The skuid.utils object provides convenient functions for commonly used functionality in Nintex Apps .Properties
Property | Type | Required | Description |
---|---|---|---|
skuid.utils.isMultiCurrencyOrganization | boolean | No |
True if this Salesforce.com organization / environment has the Multi-Currency feature enabled. |
skuid.utils.userInfo | object | No |
An object containing various fields from the running user's User object, including but not limited to:
|
skuid.utils.userLocale | object | No |
An object containing various fields describing the running user's Locale, including:
|
Functions
skuid.utils.areConditionsMet()
skuid.utils.capitalizeFirst()
skuid.utils.combineUrls()
skuid.utils.conditionallyDo()
skuid.utils.conditionallyRender()
skuid.utils.contains()
skuid.utils.convertCurrency(value,fromIsoCode,toIsoCode)
Converts a currency value from one ISO currency to another, based on the conversion rates defined in the Salesforce.com organization. (Only available for Multi-Currency organizations)
Arguments: | Returns: | Return type: |
---|---|---|
| The converted currency amount -or- the original value if one or both ISO codes were not recognized or no currencies were defined for the current org or the current org does not support multiple currencies. | number |
skuid.utils.createModal(modalDef,context,parentComponent)
Creates an Ink modal from a component definition.
Arguments: | Returns: | Return type: |
---|---|---|
| The modal |
skuid.utils.decodeHTML(value)
Decodes html characters like & into their actual character.
Arguments: | Returns: | Return type: |
---|---|---|
| A decoded HTML string. For example, where "&" and ">" have been converted into "&" and ">". | string |
skuid.utils.decodeXML()
skuid.utils.delayEventCallback()
skuid.utils.delayInputCallback(inputElement,callback)
A delayed on-change handler for an input element, which waits for a user to stop typing for 400 milliseconds before calling a callback function with the new and old values of the input element. The purpose of this function is to improve the user experience of on-change handlers, such that logic is not executed immediately upon a single change to a given field but rather only when a user "finishes" typing temporarily.
Arguments: | Returns: |
---|---|
| No return value. |
EXAMPLE:
The following Custom Field Renderer snippet will console log a field's value after the user has "stopped" typing.
{
var field = arguments[0],
value = skuid.utils.decodeHTML(arguments[1]);
// Run the default renderer
skuid.ui.getfieldRender(field.metadata.displaytype)[field.mode](field,value);
if (field.mode==='edit') {
var input = field.element.find(':input');
skuid.utils.delayInputCallback(input,function(newValue,oldValue){
console.log('[' + field.id + '] New value: ' + newValue +', old value: ' + oldValue);
});
}
skuid.utils.doArraysIntersect()
skuid.utils.doesRowMeetConditions()
skuid.utils.encodeHTML(value)
Encodes html characters like & into their encoded value like &.
Arguments: | Returns: | Return type: |
---|---|---|
| An HTML-encoded string where special characters have been escaped. For example, where "&" and ">" have been converted into "&" and ">". | string |
skuid.utils.endsWith()
skuid.utils.escapeSelector()
skuid.utils.escapeSingleQuotes(value)
Escapes single quotes in a string.
Arguments: | Returns: | Return type: |
---|---|---|
| The input string where single quotes have been escaped with a backslash. For example, given the input "O'Reailly", this function would return "O'Reilly". | string |
skuid.utils.generateGUID()
Generates a Unique Identifier within a Nintex Apps page.
Returns: | Return type: |
---|---|
A unique identifier within the current context. | string |
skuid.utils.generateUniqueId()
Arguments: | Returns: | Return type: |
---|---|---|
| The value of the property at the given path. If no such property exists, will return undefined. | string, number, boolean, object, null, undefined |
EXAMPLE
var obj = {
"Account": {
"Parent": {
"Name": "ACME Global",
"Type": "Customer"
},
"Name": "Acme USA"
},
"AccountId": "001000000034632"
};
skuid.utils.getObjectProperty(obj, "Account.Name");
// => "ACME USA"
skuid.utils.getObjectProperty(obj, "Account.Parent.Name");
// => "ACME Global"
skuid.utils.getUrlFromAttachmentId(attachmentId)
Generates a URL to the raw attachment file. Useful for creating a download link or for displaying images on the page.
Arguments: | Returns: |
---|---|
| A URL for the attachment. Useful for downloading content or displaying images within an IMG tag. The format typically looks something like this: |
/servlet/servlet.FileDownload?file=<18-character Id>
Return type: |
---|
string |
skuid.utils.getXML(xmlNode)
Takes an XML Node / Document and outputs an XML string representation of it.
Arguments: | Returns: | Return type: |
---|---|---|
| A string representation of the provided XML node or document | string |
EXAMPLE
var xmlString = '<books><book name="Travels with Charley"/><book name="The Brothers Karamazov"/></books>';
var xmlDoc = skuid.utils.makeXMLDoc(xmlString);
xmlDoc.append(
skuid.utils.makeXMLDoc('<book name="Hyperion"/>')
);
var newXmlString = skuid.utils.getXML(xmlDoc[0]);
console.log(newXmlString);
-> <books><book name="Travels with Charley"/><book name="The Brothers Karamazov"/><book name="Hyperion"/></books>
skuid.utils.hasObjectProperty(object,propertyName)
Returns true if a given JavaScript object has a property at an arbitrarily nested location, specified using a dot-notation path.Arguments: | Returns: | Return type: |
---|---|---|
| True if the object contains a property at the given path, otherwise false. | boolean |
EXAMPLE
var obj = {
"Account": {
"Parent": {
"Name": "ACME Global",
"Type": "Customer"
},
"Name": "Acme USA"
},
"AccountId": "001000000034632"
};
skuid.utils.hasObjectProperty(obj, "Account.Name");
// => true
skuid.utils.hasObjectProperty(obj, "Account.Parent.OwnerId");
// => false
skuid.utils.makeXMLDoc(xmlString)
Parses a string of XML and generates a jQuery-wrapped XML Document. Useful for generating XML for use in dynamic creation of Nintex Apps Models and Components.
Arguments: | Returns: | Return type: |
---|---|---|
| A jQuery object wrapping the parsed XML Document. | jQuery object |
EXAMPLE
// Build a set of tabs that we'd like to add to a tab set
var tabNames = ["Animals","Vegetables","Minerals"];
// Generate a Tab Set XML document
var $xml = skuid.utils.makeXMLDoc;
var tabsetXml = $xml('<tabset/>').append(
$xml('<tabs/>').append(skuid.$.map(tabNames,function(tabName){
return $xml('<tab/>').attr('name',tabName);
}))
);
// Generate a Tab Set component and add it to the bottom of the first skuidpage component
var tabsetComponent = skuid.component.factory({ definition: tabsetXml });
tabsetComponent.element.appendTo(
skuid.component.getByType('skuidpage')[0].element
);
skuid.utils.merge(mode,template,options,model,row)
Evaluates a Nintex Apps merge template, using Nintex Apps's Template syntax, in the desired mode.
Arguments: | Returns: |
---|---|
| jQuery-wrapped HTML. If you would like to return text, then use skuid.utils.mergeAsText() instead. |
skuid.utils.mergeAsText(mode,template,options,model,row)
Evaluates a Nintex Apps merge template, using Nintex Apps's Template syntax, in the desired mode.
Arguments: | Returns: |
---|---|
| A text string containing the result of the merge. |
skuid.utils.mergeAsTextInContext(template,context[,mergeSettings])
Evaluates a Nintex Apps merge template, using Nintex Apps's Template syntax, using whatever model and/or row context is provided.
The mode used for the merge is determined automatically by the presence of model and/or row properties in the optional context object - if model is provided and resolves to a valid Nintex Apps Model, then the merge mode will be "model", and if a row is provided, then the merge mode will be "row", but if neither "model" or "row" is provided then the mode will be "global".
Arguments: | Returns: |
---|---|
| A text string containing the result of the merge. |
skuid.utils.setObjectProperty(object,propertyName,propertyValue)
Sets the value of an arbitrarily nested property on a JavaScript object using a dot-notation path.Arguments: |
---|
|
EXAMPLE
var obj = {
"Account": {
"Parent": {
"Name": "ACME Global",
"Type": "Customer"
},
"Name": "Acme USA"
},
"AccountId": "001000000034632"
};
skuid.utils.getObjectProperty(obj, "Account.Parent.Type");
// => "Customer"
skuid.utils.setObjectProperty(obj, "Account.Parent.Type", "Partner");
skuid.utils.getObjectProperty(obj, "Account.Parent.Type");
// => "Partner"
skuid.utils.size(object)
Returns the number of properties defined on the provided object. Essentially a shortcut for Object.keys(object).length
Arguments: | Returns: | Return type: |
---|---|---|
| Number of properties defined on the object | number |
var obj = { "uno": "one", "dos": "two" };
skuid.utils.size(obj);
// => 2
Examples
For these examples, we'll assume that we have a Nintex Apps Page with 3 Models:
# "Account" - limited to one Account, with various Account fields pulled in # "Contacts" - all Contacts on the Account in our first Model # "Opportunities" - all Opportunities on the Account in our first Model
# "Account" - limited to one Account, with various Account fields pulled in
# "Contacts" - all Contacts on the Account in our first Model.
# "Opportunities" - all Opportunities on the Account in our first Model.
// Define the DOM element we want to write to
var output = $('#output');
// 1. Global merge examples
var template = '<b>{{$Model.Opportunities.labelPlural}} Tab</b>';
output.append(
skuid.utils.merge('global',template)
);
// --> displays 'Opportunities Tab', or the localized equivalent
template = '{{$Model.Account.fieldsMap.Name.label}}: {{#$Model.Account.data}}{{Name}}{{/$Model.Account.data}}';
output.append(
skuid.utils.merge('global',template)
);
// --> displays 'Account Name: ACME Recruiting'
// 2. Model merge examples
// We'll build an HTML table.
template = '<table>';
// We'll populate the headers of each table column
// by pulling from the metadata of each 3 fields in our Model,
template += '<thead>';
template += '<th>{{Model.Fields.Name.label}}</th>';
template += '<th>{{Model.Fields.StageName.label}}</th>';
template += '<th>{{Model.Fields.CloseDate.label}}</th>';
template += '</thead>';
// We'll populate the body of our table
// by looping over the data rows in our Model,
// using Mustache section syntax,
// and creating <td> cells populated with each rows corresponding data.
template += '<tbody>'template += '{{#Model.Data}}';
template += '<tr>';
template += '<td>{{Name}}</td>';
template += '<td>{{StageName}}</td>';
template += '<td>{{CloseDate}}</td>';
template += '</tr>';
template += '{{/Model.Data}}';
// If we have NO data rows,
// we'll using Mustache's inverted section syntax to display a message
template += '{{^Model.Data}}';
template += '<tr><td colspan="3">There are no Opportunities to display on this Account.</td></tr>';
template += '{{/Model.Data}}';
template += '</tbody>';
template += '</table>';
output.append(
skuid.utils.merge('model',template,{},skuid.model.getModel('Opportunities'))
);
The following "row" merge variables are only available in the row merge context:
- first: true if this is the first Row in the Model's data
- last: true if this is the last Row in the Model's data
- index: returns the index of this row in the Model's data