How to populate service dialog text box with ruby calculated value?

Hello team,

I was wondering if it’s possible to use “$evm.root[‘user’].get_tags” ruby variable to set the default value on a text box in a custom service dialog ?
This way I can set a read only value in my dialog depending on user ordering a service.

Thank you all,

Flintd12

Hi there,

Yes it’s possible to do what you’re asking using a dynamic method to populate the text box. The method can write the text, set the text box to readonly, or even hide/unhide it, depending on what you need. By the way there is no get_tags method, you can just use the tags method to read the tags on an object. Using tags from automate is described here: Using Tags from Automate · Mastering Automation in CloudForms 4.2 and ManageIQ Euwe

Hope this helps,
pemcg

1 Like

Hi pemcg,

Thank you very much for your answer. I used tags from the user group to set value to a dropdown, it works fine. Here is the ruby code from my method, it could be useful if someone have the same issue :

user = $evm.root[‘user’]
tags = user.miq_group.tags(“department”)
list_tags = {}
tags.each do |tag|
list_tags.store(tag,tag)
end
$evm.object[‘values’] = list_tags

My next issue is to find all tags available in a category, even if the group or the user is not tagged, do you have any idea on how to do that ?

Have a great day,
Flintd12

Have a look at the section " Getting the List of Tags in a Category" in that chapter.

pemcg

1 Like

I got to learn how to read documentation till the end… :sweat_smile:
Thank you very much @pemcg, it works just fine.

Flintd12