Mobile Metadata Expression Syntax

Configurability in the mobile web app is achieved through creating a new mobile layout JSON file and attaching to a user preference. The mobile layout defines the content of the screens and by changing the values in this JSON, different values can be displayed on the screen. For example, if you would like to see something other than the Shipment XID in the app, you can point to another field from the shipment JSON data. The system uses an expression syntax to more easily retrieve values from the JSON payload.

Values from the Top Level

The simplest values to replace are those from the top-level object such as Shipment. For example, the Shipment XID is displayed by default in the secondary header position in the Shipment List page.

"shipmentList": {
        "primaryHeader": "firstEquipmentGroupGid",
        "secondaryHeader": "shipmentXid",
        "tertiaryHeader": "",
        "showServiceProvider": true,
        "sourceLocation": [
            "locationName",
            "city",
            "provinceCode"
        ],
        "destLocation": [
            "locationName",
            "city",
            "provinceCode"
        ]

    }

If you wanted to see the value of the user defined attribute 1 field, instead of the shipment XID you can change the secondary header to be:

"secondaryHeader": "attribute1"

Values from the Secondary Level

By using the expression syntax, you can traverse the JSON structure. For example, given the following JSON:

"stops": {
        "hasMore": false,
        "limit": 25,
        "count": 2,
        "offset": 0,

If you would like to show the number of stops, from the count property you could reference it as:

“stops/count”

Paths can be traversed deeply using forward slash “/” to get to each level.  

Values in Arrays

Path traversals can also be done with arrays. This is achieved using brackets with the zero-based array index, or the keyword $last which is the last element of the array.

"stops": {
  "hasMore": false,
  "limit": 25,
  "count": 2,
  "offset": 0,
  "items": [
  {
    "stopNum": 1,
    "locationGid": "PHL",

Given the above JSON if you want to see the locationGid of the first stop, the expression would be written as:

“stops/items[0]/locationGid”

Alternatively, if you want to see the stopNum of the last stop, the expression would be:

“stops/items[$last]/stopNum”

Complex Expressions

In addition to traversing the array using a numerical index, it is also possible to use a criteria expression. For example, to get the shipmentRefnumValue below from an array in A of reference numbers, the following syntax in B can be used:

A

"refnums": {
        "items": [
            {
                "shipmentRefnumQualGid": "GLOG",
                "shipmentRefnumValue": "GUEST.MTH-REST-SHIP-001",
                "domainName": "GUEST",
                "insertDate": {
                    "value": "2020-08-06T13:10:57Z"
                }
            }

B

“refnums/items[shipmentRefnumQualGid eq ‘GLOG’]/shipmentRefnumValue”

The expression is within the square brackets. The first part of the expression is the JSON property to test. Next is the operator. Note that only eq(equals) is supported. This is followed by the criteria, in this case the string qualifier of GLOG. Datatypes for the criteria qualifiers include String (within single quotes), Boolean values such as true and false without quotes, and numerical values, without quotes.

These concepts can be combined to create complex expressions. For example, the following expression looks up the sShipUnitGid of the stop with stopNum equal to 2, and takes the first details object from the array to access the sShipUnitGid property:

"stops/items[stopNum eq 2]/details/items[0]/sShipUnitGid"

Format Functions

In some cases, certain properties would benefit from formatting before being displayed in the UI. There are several formatting functions that can be used to achieve these common use cases. Formatting functions can be applied by adding a pipe symbol ‘|’ along with the name of the function. The functions available include:

xidFromGid

Parses the XID from a GID value by removing the Domain Name if present. If the property in the OTM Rest API referenced in the mobile layout is a GID field, such as:

"sShipUnitGid": "GUEST.MTH-REST-SSU-001"

The XID can be displayed in the mobile web app using xidFromGid. The syntax is:

“sShipUnitGid | xidFromGid”

The result would be:

MTH-REST-SSU-001

uomFormatter

Used with UOMs such as weight and volume. If a UOM field is referenced in the mobile layout this function can be used to display the value along with the UOM code. UOMs such as weight and volume are defined as objects in the JSON returned by the Rest API. For example, totalWeight is defined as:

"totalWeight": {
  "value": 308.64,
  "unit": "LB"
}

In order to display the value and the unit of measure the mobile layout would be written as:

“totalWeight | uomFormatter”

The result would be:

308.64 LB

currencyFormatter

Used with currency fields. Like uomFormatter, if a currency field is referenced in the mobile layout this function can be used to display the value along with the currency code. The currency JSON format is similar to the format for UOM. It is represented as an object with properties for the value and the currency code. For example, this is the JSON for totalActualCost:

"totalActualCost": {
  "value": 12.0,
  "currency": "CAD"
}

To display the value along with the currency code the mobile layout would be written as:

"totalActualCost | currencyFormatter”

The result would be:

12.0 CAD

currencyTwoDecimalFormatter

Truncate the value to 2 decimal places. Similar to currencyFormatter but truncates the result to 2 decimal places.

Related Topics