Automate Expression Methods

automate

#1

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
YourDomain/System/Request/Tagged_Instances

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

Create an Automate Method in

YourDomain/System/Request/Tagged_Instances

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: ${/#dialog_environment.first.name}
             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
arg1
arg2
arg3

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
${/#dialog_environment.first.name}

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

Complex Service Dialog - dynamic elements visibility
#2

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.


#3

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


#4

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


#5

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


#6

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


#7

Yes