Using expressions

Using expressions

Introduction

For some entity type attributes an expression can be set that determines whether or not a condition is true based on the attribute values e.g. to determine whether values are valid. The expression format is based on the Magma JavaScript API.

Examples

The following expression returns true when the value of attribute 'myAttributeName' of an entity only contains alphanumberic characters:

$('myStringAttributeName').matches(/^[a-z0-9]+$/i).value()

In this example:

  • '$(...)' is the selector

  • 'myStringAttributeName' is an attribute name

  • 'matches' is a chaining operation

  • 'value' is a terminal operation

Chaining operations allows you to express complex expressions:

$('myIntAttributeName').gt(3).and($('myIntAttributeName').lt(6)).value()

Chaining operations

Numerical operations

Binary operations

Unit operations

Other

Terminal operations

Special case: reference types

If an attribute is a reference type (MREF, XREF, CATEGORICAL, CATEGORICAL_MREF) you can use the 'attr' operation, to access the values of different columns in the row being referenced. E.g. $('cookie').attr('name').value() gives you the value of the name column inside the table being referenced by the cookie column. See below for a more detailed example.

Imagine table A referencing table B.

Table A has 2 columns: id, cookie. Table B has 3 columns: id, name, tastiness.

The cookie column in table A references table B.

Table A

Table B

Expressions allow you to do the following

// Expressions are based on table A

$('cookie').value() // results in '1'
$('cookie').attr('id').value() // results in '1'
$('cookie').attr('name').value() // results in 'Chocolate chip'
$('cookie').attr('tastiness').value() // results in '9/10'

In the following case, we have Table A which has multiple references to Table B e.g. an MREF

Table A

Table B

// Expressions are based on table A

$('cookies').map(function (cookie) {
    // Pick one of the following
    return cookie.value()                   // results in ['1', '2', '3']
    return cookie.attr('id').value()        // results in ['1', '2', '3']
    return cookie.attr('name').value()      // results in ['Chocolate chip', 'Strawberry cookie', 'Banana cookie']
    return cookie.attr('tastiness').value() // results in ['9/10', '10/10', '7/10']
}).value()

Last updated