Archetype representing a single record for a businness object.
As it mostly covers use-cases related to work with a form it also provides operations related to the bound Business Object, for example save one record or get viewed record.
- Version:
- 16.3.5
- Source:
Extends
Methods
getEntity() → {entity/js/api/Entity}
stable API
Returns entity instance this archetype is bound to.
Note that there are cases when this may be undefined
,
such as when the entity is not found in the data model.
- Version:
- 16.3.5
- Inherited From:
- Source:
Returns:
entity the archetype is bound to. In special
occassions when the archetype is broken this may return undefined
.
- Type
- entity/js/api/Entity
Example
// expecting you have an instance of a page view model assigned to 'self'
// as this will often be the case in business actions code.
var pageViewModel = self;
var archetypeIds = Object.keys(pageViewModel.Archetypes);
archetypeIds.forEach(function (archetypeId) {
// get instance of bound entity for an archetype
var entity = pageViewModel.Archetypes[archetypeId].getEntity();
// you should always check if the value is defined as in rare cases
// the archetype may not give you the reference to its entity
if (entity) {
// print its name
console.log('Page contains an archetype with BO: ' + entity.getName());
}
});
getId() → {String}
stable API
Returns archetype's ID.
The ID is unique inside an ABCS page, not across whole ABCS application.
- Version:
- 16.3.5
- Inherited From:
- Source:
Returns:
- Type
- String
getObservables() → {viewmodel/js/api/DetailArchetype~DetailObservables}
stable API
Returns an object that contains a set of fields and observables you can bind to in your components and use to communicate with other components on a page bound to the same fields.
- Version:
- 16.3.5
- Overrides:
- Source:
Returns:
observables exposed by the archetype
getRecord() → {viewmodel/js/api/Record}
stable API
Returns current record represented by this archetype instance. The returned object can be used to alter current record data.
You will need to get the record for the most of Navigation API methods when passing data between pages, see an example below.
- Version:
- 16.3.5
- Source:
Returns:
object holding current data
Example
var customerToEdit = ContextualData.createRecordToEditContext({
// what business object are these data of:
entityId: 'customer',
// pass the currently viewed customer record
data: customerDetailArchetype.getRecord()
});
// navigate to the customer edit page
Abcs.Pages().navigateToPage('customerEditPage', customerToEdit);
getType() → {viewmodel/js/api/ArchetypeType}
stable API
Returns type of the archetype.
Type defines the archetype's behaviour, methods, fields and observables. Currently known types are:
- ArchetypeType.COLLECTION identifies a CollectionArchetype working with collections.
- ArchetypeType.ENTITY_DETAIL identifies a DetailArchetype working with single record.
- Version:
- 16.3.5
- Inherited From:
- Source:
Returns:
save(record) → {Promise}
stable API
Save the given record, that is create or update a record according to its state.
The state is determined by the way the archetype's owning page was opened and what ContextualData passed to the page through the Navigation API. If e.g. ContextualData.createRecordToEditContext is used to create the data passed to the page, the archetype will be in the edit mode. On the other hand ContextualData.createStartWithBlankRecordContext determines the create mode.
The method merely saves the passed record and stays on the same page. If you wish to pass the saved record forward to another page (such as move to a detail page after saving the record) you will need to use the Navigation API manually to do so.
Parameters:
Name | Type | Description |
---|---|---|
record |
viewmodel/js/api/Record | to save |
- Version:
- 16.3.5
- Source:
Returns:
promise resolved to saved record instance when the save successfully finishes and rejected in case of an error.
- Type
- Promise
Example
// get the current live archetype's instance of a Record
var customerRecord = customerEditArchetype.getRecord();
// get number of orders the customer has made so far
var numberOfOrders = customerRecord.getValue('numberOfOrders');
// check if number of orders is more than five and promote the customer
// to a Premium state
if (numberOfOrders > 5) {
customerRecord.setValue('state', 'Premium');
// save the modifications
customerEditArchetype.save(customerRecord).then(function () {
console.log('Successfully saved.');
});
}
Type Definitions
DetailObservables
stable API
Contains set of fields and observables you can bind to in your components and use to communicate with other components on a page bound to the same fields.
Besides the published observables you may use archetype's methods to interact with it.
Properties:
Name | Type | Description |
---|---|---|
record |
Object.<String, ko.observable> | map of ko observables wrapping values of all fields of the Business Object the archetype is bound to. Unlike DetailArchetype.getRecord this allows you to bind your HTML view directly to the field value and read or modify it immediately via ko binding. See the example below. |
item |
Object.<String, ko.observable> | Deprecated, use DetailObservables.record instead. Map of ko observables |
- Version:
- 16.3.5
- Source:
Examples
<label for="customerLastName">Customer last name</label>
<input id="customerLastName" data-bind="value: $root.Observables.customerFormArchetype.record.lastName"></input>
// subscribe to the ko observable to catch its value changes
var record = pageModel.Observables.customerFormArchetype.record;
var subscription = record.refToCustomer.subscribe(function (newCustomerId) {
console.log('New Customer ID value is: ' + newCustomerId);
// do something here related to your model
});
...
// do not forget to dispose the listener when no longer needed.
subscription.dispose();