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

Class: viewmodel/js/api/Record

Represents and wraps single data record.

You will often use this object instead of a plain JS map object when using the ABCS Navigation API or communicating with ABCS Archetypes.

In contrast to a plain JS object this provides a set of helper methods when accessing wrapped data and mainly allows you to access (and update) values of archetype's observables and record model from your code (see the example below).

Version:
  • 16.3.5
Source:
See:
Examples

Custom code accessing a form archetype, getting one of record model values and updating the value

// 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 in which case promote the
// customer to a Premium state
if (numberOfOrders > 5) {
    customerRecord.setValue('state', 'Premium');
}

Custom code fetching customer data and immediately opening the customer's detail page

require([
    'operation/js/api/Conditions',
    'operation/js/api/Operator',
    'viewmodel/js/api/ContextualData',
    'viewmodel/js/api/Record'
], function (Conditions, Operator, ContextualData, Record) {
    // construct read condition for customer with customerId=100
    var customer = Abcs.Entities().findById('my.custom.bop.Customer');
    var customerId = customer.getProperty('customerId');
    var condition = Conditions.SIMPLE(customerId, Operator.EQUALS, 100);
    // get read operation for the constructed condition
    var operation = Abcs.Operations().read({
        entity: customer,
        condition: condition
    });

    // fetch customer data
    operation.perform().then(function(operationResult) {

        // when data are fetched prepare the record to pass to a detail page
        var customerRecord = Record.createFromJSON(operationResult.getData());

        // open a detail page with id 'customerDetail' and pass the record
        // wrapped in the contextual data so the page can show its details
        // in the UI
        var customerToEdit = ContextualData.createRecordToEditContext({
            entityId: 'customer',
            // pass the record instance here
            data: customerRecord
        });
        return Abcs.Pages().navigateToPage('customerDetail', customerToEdit);
    });
});

Methods

(static) createFromJSON(data) → {viewmodel/js/api/Record}

stable API

Creates simple record backed by plain JSON object literal.

Parameters:
Name Type Description
data Object

JSON with initial values

Version:
  • 16.3.5
Source:
Returns:

created record instance

Type
viewmodel/js/api/Record
Example

Clone the Record object using Record's createFromJSON() and getDefinition() methods

// creates data for this sample
var data = {
    prop1: 'value1',
    prop2: 'value2
}
// creates the Record objects
var record = Record.createFromJSON(data);
// clones the Record
var clone = Record.createFromJSON(record.getDefinition());

getDefinition() → {Object}

stable API

Return record data as plain JSON object.

This is useful when you want to pass the record data to a remote REST endpoint via the Operations API.

Version:
  • 16.3.5
Source:
Returns:
Type
Object
Example

Clone the Record object using Record's createFromJSON() and getDefinition() methods

// creates data for this sample
var data = {
    prop1: 'value1',
    prop2: 'value2
}
// creates the Record objects
var record = Record.createFromJSON(data);
// clones the Record
var clone = Record.createFromJSON(record.getDefinition());

getProperties() → {Array.<String>}

stable API

Returns array of record's property names.

Version:
  • 16.3.5
Source:
Returns:

list of all property names

Type
Array.<String>

getValue(property) → {*}

stable API

Get value of a single property.

Parameters:
Name Type Description
property String

property ID

Version:
  • 16.3.5
Source:
Returns:

property value, may be undefined if the property doesn't exist

Type
*

setValue(property, value)

stable API

Set value of a single property.

In case the record is based on detail archetype's data this writes through the archetype's model and allows you to communicate with other components bound to the same property.

Parameters:
Name Type Description
property String

property ID

value Object

value to set

Version:
  • 16.3.5
Source: