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

Class: module:api/js/Operations

Operation API shorthand module.

Version:
  • 15.4.5
Source:

Methods

(static) create(params) → {operation/js/api/Operation}

stable API

Creates an instance of 'create' operation.

Parameters:
Name Type Description
params Object

Object literal with all possible parameters.

Properties
Name Type Description
entity entity/js/api/Entity

Entity which is this operation working over

record module:api/js/Operations~Record

Data of the record that is supposed to be created.

Version:
  • 15.4.5
Source:
Returns:
Type
operation/js/api/Operation
Example

Creates and performs operation which insert new record of Employee entity

var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var operation = Abcs.Operations().create({
    entity: employee,
    record: {
        firstName: 'Martin',
        lastName: 'Janicek',
        age: 28
    }
});

operation.perform().then(function(operationResult) {
    if (operationResult.isSuccess()) {
        // Insert code you want to perform after record being created
    }
}).catch(function(operationResult) {
    if (operationResult.isFailure()) {
        // Insert code you want to perform if record creation failed
    }
});

(static) delete(params) → {operation/js/api/Operation}

stable API

Creates an instance of 'delete' operation.

Parameters:
Name Type Description
params Object

Object literal with all possible parameters.

Properties
Name Type Description
entity entity/js/api/Entity

Entity which is this operation working over

record module:api/js/Operations~Record

Data of the record that is supposed to be deleted.

Version:
  • 15.4.5
Source:
Returns:
Type
operation/js/api/Operation
Example

Creates and performs operation which delete a single record of Employee entity

var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var operation = Abcs.Operations().delete({
    entity: employee,
    record: {
        id: 1
    }
});

operation.perform().then(function(operationResult) {
    if (operationResult.isSuccess()) {
        // Insert code you want to perform after record being deleted
    }
}).catch(function(operationResult) {
    if (operationResult.isFailure()) {
        // Insert code you want to perform if record deletion failed
    }
});

(static) read(params) → {operation/js/api/Operation}

stable API

Reads all records matching the given restrictions.

Parameters:
Name Type Description
params Object

Object literal with all possible parameters.

Properties
Name Type Attributes Description
entity entity/js/api/Entity

Entity which is created Operation working on

properties Array.<entity/js/api/Property> <optional>

Optional sub-set of Properties that should be returned by the Operation

sortBy operation/js/api/Sorting <optional>

Sorting to get records in certain order.

expand operation/js/api/ExpandableReference | Array.<operation/js/api/ExpandableReference> <optional>

Either single instance or an array of ExpandableReferences, one for each reference you want to expand.

condition operation/js/api/Condition <optional>

Condition to fetch only records matching the given criteria.

pagination operation/js/api/PaginationRequest <optional>

PaginationRequest to fetch only certain subset of records.

customData Object <optional>

Non-standard custom data which Operation author can use any way (s)he need. To learn what an Operation accepts as custom parameters, consult documentation for the BOP you imported into your app.

Version:
  • 15.4.5
Source:
See:
Returns:
Type
operation/js/api/Operation
Examples

Creates and performs Operation which reads multiple records of the Employee entity restricted by the given Condition.

require([
    'operation/js/api/Conditions',
    'operation/js/api/Operator'
], function(Conditions, Operator) {
    var employee = Abcs.Entities().findById('my.custom.bop.Employee');
    var firstName = employee.getProperty('firstName');
    var condition = Conditions.SIMPLE(firstName, Operator.EQUALS, 'Martin');
    var operation = Abcs.Operations().read({
        entity: employee,
        condition: condition
    });

    operation.perform().then(function(operationResult) {
        if (operationResult.isSuccess()) {
            // Insert code you want to perform after records are fetched
        }
    }).catch(function(operationResult) {
        if (operationResult.isFailure()) {
            // Insert code you want to perform if fetching of records failed
        }
    });
});

Creates and performs Operation reading records of the Employee entity sorted by their firstname in ascending order.

require([
    'operation/js/api/Sorting'
], function(Sorting) {
    var employee = Abcs.Entities().findById('my.custom.bop.Employee');
    var firstName = employee.getProperty('firstName');
    var operation = Abcs.Operations().read({
        entity: employee,
        sortBy: Sorting.ascending(firstName)
    });

    operation.perform().then(function(operationResult) {
        // Insert code for Success/Failure handling
    });
});

Fetch second page (assuming page is 15 records) of employees with firstname 'Martin'.

require([
    'operation/js/api/Conditions',
    'operation/js/api/Operator',
    'operation/js/api/PaginationRequest'
], function(
        Conditions,
        Operator
        PaginationRequest
) {
    var employee = Abcs.Entities().findById('my.custom.bop.Employee');
    var firstName = employee.getProperty('firstName');
    var condition = Conditions.SIMPLE(firstName, Operator.EQUALS, 'Martin');
    var pagination = PaginationRequest.createStandard({
        offset: 15,
        pageSize: 15
    });
    var operation = Abcs.Operations().read({
        entity: employee,
        condition: condition,
        pagination: pagination
    });

    operation.perform().then(function(operationResult) {
        // Insert code for Success/Failure handling
    });
});

Fetch all employee records and expand reference to Department so that it don't contain just ID but instead the whole department record is embedded.

require([
    'operation/js/api/ExpandableReference'
], function(
        ExpandableReference
) {
    // Creates an expandable reference for all relations between Employee and Department entities
    var employee = Abcs.Entities().findById('my.custom.bop.Employee');
    var department = Abcs.Entities().findById('my.custom.bop.Department');
    var deptRef = ExpandableReference.create(department);

    var operation = Abcs.Operations().read({
        entity: employee,
        expand: deptRef
    });

    operation.perform().then(function(operationResult) {
        // Insert code for Success/Failure handling
        // Result will contain main data with Employees and also each Employee will have Department record embedded
    });
});

(static) update(params) → {operation/js/api/Operation}

stable API

Creates an instance of 'update' operation.

Parameters:
Name Type Description
params Object

Object literal with all possible parameters.

Properties
Name Type Description
entity entity/js/api/Entity

Entity which is this operation working over

record module:api/js/Operations~Record

Data of the record that is supposed to be updated.

Version:
  • 15.4.5
Source:
Returns:
Type
operation/js/api/Operation
Example

Creates and performs operation which updates already existing record of Employee entity

var employee = Abcs.Entities().findById('my.custom.bop.Employee');
var operation = Abcs.Operations().update({
    entity: employee,
    record: {
        firstName: 'Martin',
        lastName: 'Janicek',
        age: 29
    }
});

operation.perform().then(function(operationResult) {
    if (operationResult.isSuccess()) {
        // Insert code you want to perform after record being updated
    }
}).catch(function(operationResult) {
    if (operationResult.isFailure()) {
        // Insert code you want to perform if record update failed
    }
});

Type Definitions

Record

Object representing single record.

Type:
  • Object.<String, String>
Source: