Automate Expression Methods

In the G release of Automate we have added support for Expression Methods.
Expression methods are built on top of MiqExpression that you see in other parts of CFME used to define advanced search, filters, reporting etc.

The advantages of expression methods are

  1. No ruby code
  2. Runs faster since it doesn’t run Automate methods via DRb
  3. Prebuilt for Dynamic Dialogs
  4. Allows for runtime substitution of (User Parameters) from workspace objects

Example 1:
Create dynamic dialogs for displaying VM’s/Instance’s based on Environment tag

Step 1: Create Automate Instance and Expression Method

Create an Automate Instance in

Use one of the method slots and set the value to Tagged_Instances

Create an Automate Method in


Set the Method Type to be Expression

Set the Name to tagged_instances

Set the Expression Object to VM

Click on the ??? to fill in the expression

In the First Dropdown select Tag

In the Second Dropdown select Vm and Instance.My Company Tags: Environment

In the Contains Drop down leave it as empty but check the “User will input the value”

In the Input Parameters add

             Name : arg1
             Default Value: ${/}
             Data Type: String

Arguments for each “User will input the value” should have Input parameters with names like with the prefix “arg”.

If there are 3 fields then the parameters should be called

Since we are going to be using the Tag Control in the Custom Dialogs, it comes into Automate as an array thats the reason we set the default value to

We are going to use the Field name “environment” in the custom dialog, when it is sent to automate its prefixed with dialog. And is stored in the root object as dialog_environment.

Step 2:

Create a Service Dialog (Automation → Automate → Customization → Service Dialogs) with 2 fields
(1) Tag Control for Environment (Label : Environment, Name: environment)
(The environment name is used in the Expression Automate Method via substitution)
(2) Drop down for instances (Label : Instances, Name: instances) mark it as a dynamic field,

Set the Entry Point so that it points to our Instance in the Automate Model.

Edit the Environment field, Options and set Fields to Refresh => Instances, this way when the environment changes
the drop down for instances would get updated.

Step 3: Apply Environment tags to your vm’s/instance’s using Policy → Edit Tags

Step 4: Create a Generic Catalog Item and link it to the Dialog created in Step 2

Step 5: Order the service
Change the Environment
And it should list the instances based on the correct environment tag

Example 2:

Update dialog text field from an expression method.

By default the expression methods are geared towards drop downs, so if you need data for a text field you need to add additional input parameters in the expression method.

  1. attributes (data type has to be Array) contains the name of the attribute from the result object that you need in the text field.
  2. result_attr (data type has to be String) should be value
  3. result_type (data type has to be String) should be simple

Can you explain what the parameter distinct do? It is listed at the optional parameters but I cannot understand the explanation.

Also, I find the documentation confusing wrt. attributes, explaining:

A comma delimited list of attributes

This suggest one can list multiple attributes here, but I do not see how it would work and what is the usecase.

Attributes is used to get a single or multiple attributes from the resultant object of the expression

This is an example of how to get multiple attributes from the object

The output of this method would look like

Attributes can also be used to get a single value from the object so that it can be directly used in a ManageIQ service dialog text field. Which has to be a single value

The output of the method would look like

Distinct is used to fetch a specific attribute from a collection of objects as an array. e.g. To get a “distinct” list of the vendor name in a collection of vis

This is the sample expression method which says list all vm objects where the name is not null, and from that list collect the distinct vendor attribute as an array

The output looks like

1 Like

OK, so using multiple attributes is not for dialog dropdowns but intended for generic method usage?


1 Like

Hi all,

Is there a way to use the Input parameters data type NULL COALESCING for argX input ?

I try to use the NULL COALESCING like that :

  - field:
      name: arg1
      datatype: null coalescing
      default_value: "${/#dialog_provider_id}||${/#service.custom_get(:provider_id)}"

But I end up with this as input :

 INFO -- : Invoking [expression] method [/DGFIP/Integration/RedHat/ManageIQ/DynamicsDialogs/list_os_cloud_tenants] with inputs [{"arg1"=>"||272"}]

I’m using the Hammer 10 version.

Does the data type has to be STRING or does I made a syntax error ?

Thanks !

This was a bug in the input processing, you can use the NULL COALESCING now that we have merged this PR

1 Like

The fix is available in Ivanchuk and master builds after August 21.

1 Like

If you need to store the attributes in a specific object with a specific name you can use the following 2 input parameters

  • result_obj (the path of the object in the workspace. / means root object, . means the current object which is the default.)
  • result_attr the name of the attribute

If the result_obj is not specified we use the current object (result_obj = .)