Ruby code in 'validate_request' method in 'Service Provision Request Approval'

Dear all,

I use service dialogs and catalog_items in MIQ to trigger Job Templates of Ansible Tower.

I would like to customize request_validation by checking the value of some of my inputs from the service dialog. E.G. If a DataCenter being specified during the order of the service is ‘THIS_VALUE’ the operation is allowed, else not.

I found this code snippet in Control auto or manual approval of a service request through validate_request

unless %w(t2.nano t2.micro).include?(dialog_options[‘dialog_InstanceType’])
$evm.log(“info”, “Instance type too big, need a manual approval”)

But somehow I cannot customize it for my usage. My variable is ‘datacenter’ I would rather need something like

if dialog_datacenter not ‘THIS_VALUE’
$evm.log(“info”, “This DC is Not OK” )
$evm.log(“info”, “This DC is OK”)

I 'm not that familiar with Ruby and the internal MIQ Objects. So it would be great if somebody could give me a little hint.

THX in advance and best regards, Marcel.

That’s invalild ruby. I assume you want the unequal operator ( != ). not is the negate-operator (aka !).

if dialog_datacenter != 'THIS_VALUE'  # compare strings
if not dialog_datacenter  ~= /VALUE_REGEX/ # match string against regex and negate the result

There is a validate-code-button in Automate-Explorers Editor that checks syntax for you and is quite helpful is you are not familiar with ruby.