MxObject
Methods
mendix.lib.MxObject is an Object that encapsulates a specific, unique instance of an Entity in the Domain Model of the current session. It provides methods for accessing and modifying attributes.
Instances of mendix.lib.MxObject should never be instantiated manually. They are the result of calls into mx.processor such as mx.processor.get or mx.processor.create .
addReference(attr, val)
addReferences()
compare(mxobj)
This method is used to compare this MxObject to another MxObject and find out if they are identical.
Parameters
| Name |
Type |
Description |
| mxobj |
MxObject |
The MxObject to compare to. |
Returns
| Type |
Description |
| Boolean |
true if they are identical, otherwise false. |
get(attr)
This method returns the typed value of an attribute.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute whose value to return. |
Returns
| Type |
Description |
| Any |
Value of the specified attribute. |
Examples
mxobj.get("IsActive"); // true
mxobj.get("Name"); // "John Doe"
mxobj.get("LoginCount"); // 315
.getAttributes()
This method will return an Array containing the names of all the attributes in this MxObject.
Parameters
Returns
| Type |
Description |
| Array |
Array of String values of the attribute names. |
Example
var attrs = mxobject.getAttributes(); // ["Name", "Age"];
getAttributesWithoutReferences()
getEntity()
This method will return a String with this object’s Entity name.
Parameters
Returns
| Type |
Description |
| String |
String value of the Entity name. |
Example
mxobject.getEntity(); // "System.User"
.getChild(attr)
XPath queries can be performed with a depth level. If this level is greater than 0 the references that each MxObject contains are filled with the MxObjects of the references (up to the depth level).
This in that case, instead of calling getReference to get the reference GUID, this method will return the MxObject.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to retrieve the reference Object from |
Returns
| Type |
Description |
| MxObject |
MxObject for the reference. |
.getChildren()
XPath queries can be performed with a depth level. If this level is greater than 0 the references that each MxObject contains are filled with the MxObjects of the references (up to the depth level).
This in that case, instead of calling getReferences to get the reference GUID, this method will return the MxObjects in an Array.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to retrieve the references Object from |
Returns
| Type |
Description |
| Array |
Array of MxObjects |
.getEntity()
This method will return a String with this object’s Entity name.
Parameters
Returns
| Type |
Description |
| String |
String value of the entity name. |
Example
getEnumCaption(attr, key)
This method will return the (translated) value of key (if any) of the Enumeration of attribute attr .
Parameters
| Name |
Type |
Description |
| attr |
String |
The Enumeration attribute of this MxObject |
| key |
String |
The key of the Enumeration whose value to return. |
Returns
| Type |
Description |
| String |
String value of the caption. |
Example
mxobject.getEnumCaption("Color", "red"); // "Rouge"
.getEnumKeys
.getEnumKVPairs
.getEnumMap
.getEnumValue
getGUID()
This method will return the GUID of this object.
Parameters
Returns
Number
Example
mxobject.getGUID(); // 1234567890131
.getOptions(attr)
This method will return the Enumeration keys of this attribute (if any) in an Array.
Parameters
Returns
Array
Example
mxobject.getOptions("Color"); // ["red", "green", "blue"]
.getReference
.getReferenceAttributes
.getReferences
.getSelectorEntity(attr)
This method is used to get the Entity of a reference attribute.
Parameters
| Name |
Type |
Description |
| attr |
String |
The reference attribute whose Entity to return. |
Returns
| Type |
Description |
| String |
A String with the Entity name |
Example
mxobj.getSelectorEntity('Order_OrderLine'); // "CRM.OrderLine"
.getSubEntities()
This method will return an Array with the names of the Entities that inherit from this Entity (if any).
Parameters
Returns
Array
Example
mxobject.getSubEntities(); // ["MyModule.EntityA", "MyModule.EntityB"]
.getSuperEntities()
This method will return an Array with the inheritance chain of this Entity (if any).
Parameters
Returns
Array
Example
mxobject.getSuperEntities(); // ["MyModule.EntityC", "MyModule.EntityD", "System.User"]
hasChanges()
This method is used to find out if a MxObject has changes.
Parameters
Returns
| Type |
Description |
| Boolean |
true if this MxObject has changes, otherwise false |
.hasChildren
hasSubClasses()
This method is used to find out if this MxObject is an entity that inherits other entities.
Parameters
None
Returns
| Type |
Description |
| Boolean |
true if this MxObject inherits from other entities, otherwise false |
hasSuperClasses()
This method is used to find out if this MxObject is an entity that inherits other entities inherit from.
Parameters
None
Returns
| Type |
Description |
| Boolean |
true if other entities inherit from the entity of this MxObject |
inheritsFrom(entity)
This method is used to find out if this MxObject is an entity that inherits from an other specific entity.
Parameters
| Name |
Type |
Description |
| entity |
String |
The entity to check for inheritance. |
Returns
| Type |
Description |
| Boolean |
true if this MxObject inherits from entity, otherwise false |
isA(entity)
This method is used to find out if this MxObject is an instance of entity entity.
Parameters
| Name |
Type |
Description |
| entity |
String |
The entity to check for. |
Returns
| Type |
Description |
| Boolean |
true if this MxObject is an instance of entity, otherwise false |
Example
if (mxobject.isA("System.User")) {
alert("This object is a System.User");
} else {
alert("This object is not a System.User");
}
isBoolean(attr)
This method is used to find out if attribute attr is _Boolean.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| Boolean |
true if attribute attr is Boolean, otherwise false |
Example
if (mxobject.isBoolean("Amount")) {
alert("Attribute " + attr + " is a Boolean");
} else {
alert("Attribute " + attr + " is not a Boolean");
}
isCurrency(attr)
This method is used to find out if attribute attr is _Currency.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| Currency |
true if attribute attr is Currency, otherwise false |
Example
if (mxobject.isCurrency("Amount")) {
alert("Attribute " + attr + " is a Currency");
} else {
alert("Attribute " + attr + " is not a Currency");
}
isDate(attr)
This method is used to find out if attribute attr is _Date.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| Date |
true if attribute attr is Date, otherwise false |
Example
if (mxobject.isDate("DoB")) {
alert("Attribute " + attr + " is a Date");
} else {
alert("Attribute " + attr + " is not a Date");
}
isEnum(attr)
This method is used to find out if attribute attr is _Enum.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| Enum |
true if attribute attr is Enum, otherwise false |
Example
if (mxobject.isEnum("Selections")) {
alert("Attribute " + attr + " is an Enumeration");
} else {
alert("Attribute " + attr + " is not an Enumeration");
}
isLocalizedDate(attr)
This method is used to find out if attribute attr is a localized Date.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| LocalizedDate |
true if attribute attr is LocalizedDate, otherwise false |
Example
if (mxobject.isLocalizedDate("Selections")) {
alert("Attribute " + attr + " is a Localized Date");
} else {
alert("Attribute " + attr + " is not a Localized Date");
}
isNumber(attr)
This method is used to find out if attribute attr is _Number.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| Number |
true if attribute attr is Number, otherwise false |
Example
if (mxobject.isNumber("Count")) {
alert("Attribute " + attr + " is a Number");
} else {
alert("Attribute " + attr + " is not a Number");
}
.isObjectReference
.isObjectReferenceSet
isPassword(attr)
This method is used to find out if attribute attr is _Password.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| String |
true if attribute attr is Password, otherwise false |
.isReadonlyAttr
isReference(attr)
This method is used to determine is the attribute attr is a reference or not.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to check. |
Returns
| Type |
Description |
| String |
true if attribute attr is a reference, otherwise false |
.removeReferences
set(attr, val)
This method is used to set the value of attribute attr to the value of val. The type of val depends on the type of attribute.
This only changes the MxObject instance in the client session. To send the changes to the server or commit the object to the backend database, see mx.processor.save and mx.processor.commit , respectively.
Parameters
| Name |
Type |
Description |
| attr |
String |
The attribute to set. |
| val |
Any |
The value to set. |
Returns
| Type |
Description |
| Boolean |
true if change was successful, otherwise false |
Example
mxobj.set("Name", "John Smith");
mxobj.set("IsActive", true);
toString()
This method returns the GUID.
Parameters
Returns
| Type |
Description |
| String |
GUID of this MxObject |