Class

CustomEntity

CustomEntity

Base class of all entities with custom attributes.

Methods

exists() → {boolean}

Check, whether the entity referenced by this object exists.

true if object references an existing entity, false otherwise

boolean
Example
// page is a reference to a custom entity of type page
if (page.exists()) {
  // do something
}

get(internalName, enumsAsDisplayValueopt, enumLanguageopt) → {Object}

Get the current value of a given entity attribute.

Parameters:
Name Type Attributes Default Description
internalName string

the internal name of the attribute. If there is an prefix defined for the containing type this can also be just the suffix.

enumsAsDisplayValue boolean <optional>
false

If given and set to true, for enum attributes the returned value will be the localized display value, otherwise the internal name of the value will be returned. Please note that for localized enum values, the specified language will be used - when no localized value for that language is defined, then no further fallback is done and null is returned

enumLanguage string <optional>

Specifies the language name for the localized enum value. If this is not specified, the current user's language will be used (if run in a context without user session, the tenant's default language is used). If this is specified, the above parameter enumsAsDisplayValue is optional and assumed to be true.

The current value.

Object
Examples
// page is a reference to a custom entity of type page
var assignee = page.get('assignee'); // Get value of 'assignee' attribute. Will be null if not found or set
if (assignee != null) {
  // do something
}
// assume the configured prefix is 'cf.cplace.example' both calls will be equivalent:
var valueName  = page.get('value');
var valueName2 = page.get('cf.cplace.example.value');
// Attribute 'myEnum' is a text enumeration attribute
var myInternalName = page.get('myEnum');                     // Internal value
var myGermanLocalizedValue = page.get('myEnum', true, 'de'); // Enum value in German
var myOtherGermanValue = page.get('myEnum', 'de');           // Shorter way to get the German value
var myEnglishEnumValue = page.get('myEnum', 'en');           // Enum value in English

// Get the enum value in the current user's language:
var myUserLanguageEnumValue = page.get('myEnum', true);

// Get the enum value in language of a specific user:
var user = cplace.utils().findUserByLogin('user@example.com');
var userLanguage = user ? user.getUserLanguage() : null;
var userLanguageEnumValue = page.get('myEnum', true, userLanguage);

getAttributeDisplayName(internalName) → {string}

Get the localized display name of custom attribute in the language of the current session.

Parameters:
Name Type Description
internalName string

the internal name of the attribute. If there is an prefix defined for the containing type this can also be just the suffix.

Display name of attribute in current language. Will be null if the attribute is not found

string
Example
// page is a reference to a custom entity of type page
var assignee = page.getAttributeDisplayName('assignee'); // Get display name of attribute 'assignee' in current language

// assume the configured prefix is 'cf.cplace.example' both calls will be equivalent:
var valueName  = page.getAttributeDisplayName('value');
var valueName2 = page.getAttributeDisplayName('cf.cplace.example.value');

getBuiltinFeatureValue(featureName) → {boolean|string|Date|number|ArrayLike.<CustomEntity>}

Get value of a builtin feature.

Parameters:
Name Type Description
featureName string

the name of the builtin feature to get from the entity.

Current value or null if this object does not refer to an existing entity.

boolean | string | Date | number | ArrayLike.<CustomEntity>
Example
// page is a reference to a custom entity of type page
var createDate = page.getBuiltinFeatureValue('createdAt'); // Get creation date of page

getId() → {string}

Get the Uid of the entity

The Uid of the entity or null if this object does not refer to an existing entity.

string
Example
// page is a reference to a custom entity of type page
var id = page.getId(); // Get Uid of the page. Will be null if page does not reference an existing entity

getName() → {string}

Get the name of the entity

name of the entity. null if this object does not refer to an existing entity.

string
Example
// page is a reference to a custom entity of type page
var name = page.getName(); // Get name of the page. Will be null if page does not reference an existing entity

getOptional(internalName) → {Object}

Get the current value of a given entity attribute.

For single reference attributes with a null value, a CustomEntity object of the correct subtype is returned. As that object does not refer to an existing entity, exists will always return false, getter methods will always return false.

Parameters:
Name Type Description
internalName string

the internal name of the attribute. If there is an prefix defined for the containing type this can also be just the suffix.

Current value of attribute, null if no type or attribute definition for that name is found or a dummy page if the attribute is an unset single reference.

Object
Example
// page is a reference to a custom entity of type page
var assignee = page.getOptional("assignee"); // Get value of 'assignee' attribute
if (assignee.exists()) {                     // Check if assignee is set (i.e. exists)
  // do something
}

// assume the configured prefix is 'cf.cplace.example' both calls will be equivalent:
var valueName  = page.getOptional('value');
var valueName2 = page.getOptional('cf.cplace.example.value');

getRealUid() → {string}

Get the real Uid of the entity. If this entity is persistent or is a writable copy of a persistent entity, returns the UID built from persistent id of the persistent entity. Otherwise (i.e., if the entity is new) this method returns the UID built from the current id.

The real Uid of the entity or null if this object does not refer to an existing entity.

string
Example
// page is a reference to a custom entity of type page
var id = page.getRealUid(); // Get real Uid of the page. Will be null if page does not reference an existing entity

getVersionHistoryOfAttribute(entity, attributeName) → {ArrayLike.<ChangeData>}

Creates the version history of an attribute

Parameters:
Name Type Description
entity CustomEntity

the entity

attributeName string

The internal attribute name

Version history of an attribute

ArrayLike.<ChangeData>