JavaScript Application Development API for Oracle Visual Builder Cloud Service - Classic Applications

Class: viewmodel/js/api/CollectionArchetype

Archetype representing collection of records for a single businness object.

Besides a data collection itself it provides also operations applicable on a collection of records, for example retrieve data, delete one record or get selected record.

ABCS table and list components are built on top of this archetype so any interaction with an existing CollectionArchetype also affects the owner component.

Version:
  • 16.3.5
Source:

Extends

Methods

delete(input) → {Promise}

stable API

Delete given record permanently from the underlying data source.

Removes the record not only from the collection but also from any persistent data source feeding the collection with its data. Usually that means this calls a REST endpoint to remove the data.

Parameters:
Name Type Description
input Object

data to delete

Properties
Name Type Description
record viewmodel/js/api/Record

record instance to delete

Version:
  • 16.3.5
Source:
Returns:

promise resolved when the record is successfully deleted or rejected in case of a failure.

Type
Promise
Example

Delete the currently selected customer record

var customerArchetype = pageViewModel.Archetypes.customerTableArchetype;
// get the selected record
var record = customerArchetype.getSelectedRecord();
// if there is a selection delete the selected record
if (record) {
    customerArchetype.delete({
        record: record
    }).then(function () {
        console.log('Record successfully deleted');
    });
}

fetch(paramsopt)

stable API

(Re-)Fetch data into the collection. Calling this method triggers asynchronous refresh which will result into UI update when finished. Any data already loaded will be flushed and forgotten and the collection will be populated with fresh new data.

Parameters:
Name Type Attributes Description
params Object <optional>

fetch parameters

Properties
Name Type Attributes Description
condition operation/js/api/Condition <optional>

Additional Condition that will be used together with any other Condition which may have been specified during configuration of this archetype.

Version:
  • 16.3.5
Source:
Example

Fetch all customers with name equal to 'John' into a collection

require([
    'operation/js/api/Conditions',
    'operation/js/api/Operator'
], function (Conditions, Operator) {
    // construct read condition for employee with name='John'
    var employee = Abcs.Entities().findById('my.custom.bop.Employee');
    var employeeName = employee.getProperty('name');
    var condition = Conditions.SIMPLE(employeeName, Operator.EQUALS, 'John');

    // fetch employee data into the collection
    employeeArchetype.fetch({
        condition: condition
    });
});

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

List all Business Objects in all page archetypes and print their names.

// 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/CollectionArchetype~CollectionObservables}

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

Type
viewmodel/js/api/CollectionArchetype~CollectionObservables

getSelectedRecord() → {viewmodel/js/api/Record|undefined}

stable API

Returns currently selected record.

Version:
  • 16.3.5
Source:
Returns:

record with current row data or undefined if selection is empty at the moment.

Type
viewmodel/js/api/Record | undefined
Examples

Delete the currently selected customer record

var customerArchetype = pageViewModel.Archetypes.customerTableArchetype;
// get the selected record
var record = customerArchetype.getSelectedRecord();
// if there is a selection delete the selected record
if (record) {
    customerArchetype.delete({
        record: record
    }).then(function () {
        console.log('Record successfully deleted');
    });
}

Get the selected record and pass it to a detail page

var customerArchetype = pageViewModel.Archetypes.customerTableArchetype;
// get the selected record
var record = customerArchetype.getSelectedRecord();
// if there is a selection open it in a detail page
if (record) {
    var customerToDisplay = ContextualData.createRecordToEditContext({
        // what business object are these data of:
        entityId: 'customer',
        // instance of a customer to edit
        data: record
    });
    // navigate to the detail page
    Abcs.Pages().navigateToPage('customerDetailPage', customerToDisplay);
}

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:

Version:
  • 16.3.5
Inherited From:
Source:
Returns:
Type
viewmodel/js/api/ArchetypeType

Type Definitions

CollectionObservables

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.

At the moment there are no useful observables you could use for CollectionArchetype. To interact with a collection archetype you may use its public methods.

Version:
  • 16.3.5
Source: