fail to calculate formula when fields not enabled for project
spaluc opened this issue · 8 comments
For a case when computed field depends on other custom field and one of the dependent custom field is not enabled for the project, the formula fails and does not allow to update issue.
It is not surprising that formula fails, but when not all needed fields are used in the project, the formula should just not run or clear/remove the computed field value. It should not prevent from updating the issue.
It is administrator's responsibility to write safe code in a formula field.
When you would write code, you could check if a current issue (or project) has a specific field.
self.available_custom_fields.map(&:id).include?(your_id_here)
or project.available_custom_fields.map(&:id).include?(your_id_here)
This does not work. I gen an error "undefined method `first' for nil:NilClass" even if do this:
if 0
cfs[55] * cfs[56]
else
0
end
What types have fields with ids 55 and 56? Please show errors from your log file.
Hi, Annikoff
I'm facing the same problem.
I get the error: "Error while formula computing in field "Total" — undefined method `first' for nil:NilClass)"
Total formula:
if 0
cfs[108]
else
1
end
In my case, cfs[108] is a decimal field.
Mybe the file that raises the exception is the "model_patch.rb" ?
ln 36) cfv = @grouped_cfvs[cf_id].first
ln 37) hash[cf_id] = cfv ? cfv.custom_field.cast_value(cfv.value) : nil
(Sorry in the case I'm wrong, I'm totally a newbie in ruby and redmine)
Thanks in advance.
Does CF 108 exist for your issue? Because if 0
returns true
and if you try to call not existing CF value, an error could be raised.
Try this code
if available_custom_fields.map(&:id).include?(108)
cfs[108]
else
1
end
Thank you for your immediate reply !!
I'm going to try and I'll let you now.
Thanks
It works!
Thank you very much!