Closed JGallot closed 1 year ago
Hi,
You should manage the potential nil? values. Use this code to get mail address and login name:
selected_user = User.find_by_id(custom_field_value(322).to_i) unless custom_field_value(322).nil?
user_login = selected_user.login unless selected_user.nil?
user_mail = selected_user.mail unless selected_user.nil?
Note: nil is a special Ruby object used to represent an “empty” or “default” value. If your custom field is not selected, then you got nil (empty) value, and the User.find_by_id method couldn't work, because it has no id value.
The issue is same, when you try to access to login and mail attributes. If the User.find_by_id did not find any user, the selected_user value will be nil, then you cannot access to empty.mail or empty.login.
I hope it helps!
Hi, Effectivly, i was a bit lazy... yes it helps, it sound good now ! Thanks
Hello,
I've got a little question. In my issue, i've got a custom field which is User TYpe.
I can acces the value(id) of the User selected. I can get find the User object thanks to the find_by_id() method.
But i don't undertand (maybe too tired ;) ) why i can't access to User.mail or User.login values.
code example:
Error Message when trying to save custom workflow is :
Workflow script executable before saving observable object contains error: undefined method 'login' for nil:NilClass
But if a replace
raise RedmineCustomWorkflows::Errors::WorkflowError, u.login
byraise RedmineCustomWorkflows::Errors::WorkflowError, u.inspect
i can save and obtain object infos.Any ideas ?