My Use Case: Modifying A Dynamic Dialog that was accessing the vmdb Cloud flavors in a dropdown to use the Automate data store.
Here is my original dialog:
# Description: This method reads from the flavors class.
#
FLAVOR_CLASS = 'Flavor'.freeze
values_hash = {}
values_hash['!'] = '** no cloud flavors found **'
cloud_flavors = $evm.vmdb(FLAVOR_CLASS).all
unless cloud_flavors.empty?
values_hash['!'] = '-- select from list --'
cloud_flavors.each do |flavor|
values_hash[flavor.id] = flavor.name
end
end
list_values = {
'sort_by' => :value,
'data_type' => :string,
'required' => true,
'values' => values_hash
}
list_values.each { |key, value| $evm.object[key] = value }
I created an instance and a method that would retrieve all the flavors and populate Automate instances.
I ran this using Automate Simulation to build the instances. You could easily setup a cron job to do this.
Note: The class and class schema need to be manually created prior to creating instances.
# Description: This method creates automate instances from the flavors class.
#
cloud_flavors = $evm.vmdb('Flavor').all
# output goes to -> Flavors/Flavor/Data Name and Id
# Namespace and class need to be pre-built with 2 fields (name and id)
unless cloud_flavors.empty?
cloud_flavors.each do |flavor|
method = $evm.instance_create("Flavors/Flavor/Data/#{flavor.name}", "name" => "#{flavor.name}", "id" => "#{flavor.id}")
method
end
end
I modified my Dynamic Dialog to read the instances instead of accessing the vmdb Cloud flavors.
# Description: This method reads automate instances built from the flavors class.
#
values_hash = {}
values_hash['!'] = '** no cloud flavors found **'
cloud_flavors = $evm.instance_find('Flavors/Flavor/Data/*')
unless cloud_flavors.empty?
values_hash['!'] = '-- select from list --'
cloud_flavors.each do |flavor, h|
values_hash[h["id"]] = h['name']
end
end
list_values = {
'sort_by' => :value,
'data_type' => :string,
'required' => true,
'values' => values_hash
}
list_values.each { |key, value| $evm.object[key] = value }
Now when I order my service, the dialog retrieves the instance data.
A great use case for this is a Dynamic Dialog that accesses ServiceNow.