Access properties on values in expressions

Within expressions, certain types of data have properties. This article, written from the developer’s perspective, describes how to access properties on values in expressions. In Architect, the Currency data value element contains two available properties:

  • Amount: A decimal that reflects the amount of the currency
  • Code: A string that contains the ISO 4217 code for the currency.

For example, a currency with an amount of 5.00 and code of “USD” is 5 United States Dollars.

Example: Access the amount set on currency

Suppose you have a Flow.MyCurrency variable with a Currency data type, and you want to obtain the amount set on the currency. Architect supports three syntactic ways to access the Amount property. 

Method Description
Flow.MyCurrency.Amount This method is valid for any property whose name starts with a letter and is followed by one or more letters, digits or underscores.
Flow.MyCurrency.”Amount”

This method is valid for any property name, including property names that contain spaces or periods. It is important to remember that you access the property via a string literal, and standard escaping rules apply for the string literal. If a value contains a property name of AM\PM, it is not valid to access it with the syntax shown in the Flow.MyCurrency.AmountLearn example

Valid

Use a string literal as follows:

Flow.MyCurrency."AM\\PM"

In this example, use the backslash as an escape sequence inside the string literal. 

Invalid

Using the Flow.MyCurrency method, only a string literal is supported. The following example is not valid.

Flow.MyCurrency."Am"+"ount" or Flow.MyCurrency.(Am"+"ount")

If a property name contains a character that needs to be escaped, use quotes to access it. In the following example, we want to access the “AM\PM” property name on a data type. The correct string is:

Flow.ExampleVar."AM\PM"

For more information about how to escape string literals, see Use string literals in expressions.

Flow.MyCurrency[“Amount”] This method is the same as Flow.MyCurrency. However, use a bracket operator, rather than a decimal, to access the property. This method contains both an opening bracket and a closing bracket. While this notation is supported, it is not the default displayed in type-ahead functionality in expression editors. Also, the property access within the brackets must to be a string literal with appropriate escaping.

The examples above use a variable to access the amount property. Remember, you are essentially working with the currency value on the currency variable and accessing a property on that variable. For example, the following are also valid examples because MakeCurrency returns a currency value and you can access the amount from the returned currency:

  • MakeCurrency(10.00, “USD”).Amount
  • MakeCurrency(10.00, “USD”).”Amount”
  • MakeCurrency(10.00, “USD”)[“Amount”]

NOT_SET in data values

In expressions, make sure your value is set. If, for example, a Currency value is NOT_SET, you cannot access the Amount or Code property. This example is syntactically valid:

ToCurrency(NOT_SET).Amount

However, an error occurs at runtime because you cannot access the Amount property on a NOT_SET currency. Best practice recommends you confirm that a data value is NOT_SET before you access a property on it.