Accessing miq_provision_request before submission

When I run ws_hash = $evm.root['miq_provision_request'].get_option(:ws_values) I get this error in automation.log:
NoMethodError: undefined method 'get_option' for nil:NilClass
This is in an Automate script which is executed by field in my service dialog. Thus, the request has not yet been submitted and probably there is no request object to access.

Am I right to conclude that miq_provision_request (and therefore ws_values) is not avaialble before the request is submitted?

Thank you

The service dialog element methods can’t easily access the service request details. You can access the $evm.root['service_template'].service_resources.first.resource object which is the static miq_provision_request_template object that’s created when you define the service catalog item. This wouldn’t normally have a ws_values field in the option hash though, but serves as the pseudo provisioning request template for the VM provision initiated from a service.

What would have filled in the ws_values fields?

pemcg

Tip: it can be useful to just call object_walker from a service dialog element dynamic method to see what objects are available under $evm.root

pemcg

Thanks @pemcg :slight_smile: The reason I want to access ws_values is not to retrieve a property but to set a property. Our organization requires a multi-level approval process with different approvers based on the dollar value of the request and the cost center of the requester. Since I need to load multiple approvers in 1-4 fields (depending on dollar value of request), and since a script can only load values in the field that called it, I have to be able to store a variable in memory some where to coordinate between the methods as the approvers are loaded one at a time. I’ll try the spot you suggested!

I was unable to print or add a property to $evm.root['service_template'].service_resources.first.resource
So, I tried the object walker. In my method I simply called $evm.instantiate('/Discovery/ObjectWalker/object_walker') per your docs. It printed the following in automation.log:

walk_association_whitelist = {
    'MiqAeServiceServiceTemplateProvisionTask':['source','destination','miq_request','miq_request_task','miq_request_tasks','service_resource'],
    'MiqAeServiceServiceTemplateProvisionRequest':['miq_request','miq_request_tasks','requester','resource','source'],
    'MiqAeServiceServiceTemplate':['service_resources'],
    'MiqAeServiceServiceResource':['resource','service_template'],
    'MiqAeServiceMiqProvisionRequest':['miq_request','miq_request_tasks','miq_provisions','requester','resource','source','vm_template'],
    'MiqAeServiceMiqProvisionRequestTemplate':['miq_request','miq_request_tasks'],
    'MiqAeServiceManageIQ_Providers_Vmware_InfraManager_Provision':['source','destination','miq_provision_request','miq_request','miq_request_task','vm','vm_template'],
    'MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Provision':['ALL'],
    'MiqAeServiceManageIQ_Providers_Amazon_CloudManager_Vm':['availability_zone','cloud_network','cloud_subnet','cloud_subnets'],
    'MiqAeServiceManageIQ_Providers_Vmware_InfraManager_Vm':['ems_cluster','ems_folder','resource_pool','ext_management_system','storage','service','hardware','operating_system'],
    'MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Vm':['ems_cluster','resource_pool','ext_management_system','storage','service','hardware'],
    'MiqAeServiceManageIQ_Providers_Azure_CloudManager_Vm':['availability_zone','cloud_networks','cloud_subnets'],
    'MiqAeServiceManageIQ_Providers_Google_CloudManager_Vm':['flavor','floating_ip'],
    'MiqAeServiceManageIQ_Providers_Openstack_CloudManager_Vm':['miq_provision','network_ports','network_routers','operating_system'],
    'MiqAeServiceHardware':['nics','guest_devices','ports','vm'],
    'MiqAeServiceUser':['current_group','current_tenant'],
    'MiqAeServiceGuestDevice':['hardware','lan','network'],'MiqAeServiceManageIQ_Providers_Redhat_InfraManager_Template':['operating_system'],
    'MiqAeServiceManageIQ_Providers_AnsibleTower_ConfigurationManager_ConfigurationScript':['ALL'],
    'MiqAeServiceManageIQ_Providers_AnsibleTower_ConfigurationManager_Job':['ALL']
}

Looking here I didn’t see any service_template key so I tried $evm.root['MiqAeServiceServiceTemplate'].service_resources.first.resource. Going this route also proved fruitless as I cannot print or add a custom attribute there either. For example:

$evm.log(:info, "about to set value to $evm.root['MiqAeServiceServiceTemplate'].service_resources.first.resource.custom='musclecar': ")
$evm.root['MiqAeServiceServiceTemplate'].service_resources.first.resource['custom']='musclecar'
$evm.log(:info, "log that custom value, did it print musclecar? on next line?")
$evm.log(:info, $evm.root['MiqAeServiceServiceTemplate'].service_resources.first.resource['custom'])

produces the following errors:

[----] E, [2020-08-24T11:09:00.140778 #3209:19ad2c08] ERROR -- : <AEMethod ownerapproval2> The following error occurred during method evaluation:
[----] E, [2020-08-24T11:09:00.141045 #3209:19ad2c08] ERROR -- : <AEMethod ownerapproval2>   NoMethodError: undefined method `service_resources' for nil:NilC
lass
[----] E, [2020-08-24T11:09:00.141895 #3209:19ad2c08] ERROR -- : <AEMethod ownerapproval2>
[----] E, [2020-08-24T11:09:00.143489 #3209:19ad2c08] ERROR -- : Method STDERR: /EXP/Dialog/approvals/multiapproval/ownerapproval2:4:in `<main>': undefined m
ethod `service_resources' for nil:NilClass (NoMethodError)

Did you install and use the object_walker_reader? It looks like you’ve only found a small part of the output