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
- No ruby code
- Runs faster since it doesn’t run Automate methods via DRb
- Prebuilt for Dynamic Dialogs
- 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.
- attributes (data type has to be Array) contains the name of the attribute from the result object that you need in the text field.
- result_attr (data type has to be String) should be value
- result_type (data type has to be String) should be simple