The syntax that can be used to access properties within the customOptions Morpheus variable and why

Hello,

This post is to help you understand the various syntaxes for accessing properties from the customOptions Morpheus variable, and in what scenario the correct syntax should be used.

Before we get started we need to cover some background about how morpheus uses field names for option types:


  1. When creating a custom option type in Morpheus, you must specify a field name.
  2. Morpheus allows you to access the values of custom option types via the “customOptions” Morpheus variable and using the field name of the option type.
  3. The “customOptions” variable is a Map type
  4. When accessing properties of a Map (and other objects) you need to follow the correct Groovy syntax:

https://groovy-lang.org/syntax.html#_normal_identifiers

https://groovy-lang.org/syntax.html#_quoted_identifiers


With the above syntax in mind, here are some examples showing how to access a value within the customOptions variable:
Example 1
Option type X has field name “myVariable”.
To access the value of X within automation we can do any of the following:

customOptions.myVariable
customOptions["myVariable"]
customOptions."myVariable"

Example 2
Option type Y has field name “my-variable”
As the field name does not follow the “normal identifier” syntax we can access the value of Y within automation using only the following:

customOptions["my-variable"]
customOptions."my-variable"

Cheers,

Chris

2 Likes