I think there is a bug with the code you’ve posted, which might be part of your issue?
if campo3 = 2
result = “vlan ok”
end
This code is assigning the value 2 to the campo3 variable and not doing a comparison. This assignment will always evaluate to true, and thus the result will always be “vlan ok”. If you’re trying to do comparison, you want the == operator instead (i.e. if campo3 == 2)
On a related note, the variable campo3 can’t be nil, if the field dialog_campo1 exists in the dialog, it will have a default value (e.g. the empty string “”). You could use campo3.blank? which checks for nil and a couple of other cases (most notably empty strings/collections, string with only whitespaces and the boolean false)
However since you are dealing with integers: zero is not considered blank
I would write the code like this:
value = $evm.object['dialog_campo1']
if value.respond_to?(:to_i) && value.to_i == 2
result = "vlan ok"
else
result = value.to_s
end
$evm.object['data_type'] = "string"
$evm.object['required'] = true
$evm.object['value'] = result
If you don’t like the if-statement, this has the same effect. Depends on how explicit you want to be with your type checking and how comfortably you are with ruby/rails
# This if statement has the same effect as the if above
if value.try(:to_i) == 2
result = "vlan ok"
else
result = value.to_s
end