Adding Custom Field Value to Subject in Notification Email
Added by Scott Blair over 12 years ago
Someone please help save me here. I detest moding the code but need to make a simple change to add a custom field value into the Subject line on the notification emails. I've searched everywhere and come close to getting it working but am not quite there yet.
In /app/models/mailer.rb
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
I have found that adding #{issue.custom_field_values} will print out ALL the custom value fields for that issue. i.e. what I get is that values for each of these custom fields displayed: "1"=>"Arcade", "3"=>"3", "4"=>"Cyclone" what it actually displays in the Subject line for that array is "Arcade3Cyclone" but I need to just access ONE of the custom field values and not have all of them displayed.
Here are just a few of some of the things that I have tried and failed at using:
#{issue.custom_field_values[4]}
#{issue.custom_value_for(4)}
In app/views/mailer/_issue.text.erb it does print out the custom fields in the body of the email using the following:
<%=l(:field_author)%>: <%= issue.author %>
<%=l(:field_status)%>: <%= issue.status %>
<%=l(:field_priority)%>: <%= issue.priority %>
<%=l(:field_assigned_to)%>: <%= issue.assigned_to %>
<%=l(:field_category)%>: <%= issue.category %>
<%=l(:field_fixed_version)%>: <%= issue.fixed_version %>
<% issue.custom_field_values.each do |c| %><%= c.custom_field.name %>: <%= show_value(c) %>
<% end %>
<%= issue.description %>
I've tried various ways of using that code there to access a single element in the mailer.rb file for the Subject field but failed since I'm not familiar with this language enough.
Thanks for the assistance!
Scott
Replies (7)
RE: Adding Custom Field Value to Subject in Notification Email - Added by Tim Schoffelman over 10 years ago
Hey Scott - we you able to figure this out?
RE: Adding Custom Field Value to Subject in Notification Email - Added by Scott Blair over 10 years ago
Yes, I was able to eventually get it to work.
RE: Adding Custom Field Value to Subject in Notification Email - Added by Tim Schoffelman over 10 years ago
Do you happen to remember what you used, I'd like to do something similar to what you used above.
RE: Adding Custom Field Value to Subject in Notification Email - Added by Scott Blair over 10 years ago
Here's what I did:
In: /rails_apps/redmine/app/models/mailer.rb added #{custom_field_values} to the Subject line.
I never did work out how to include just 1 custom field. In the end, for this project we only ended up needing the 1 custom field so it wasn't an issue for me as worked for what I needed.
Excerpt:
message_id issue
@author = issue.author
recipients issue.recipients
cc(issue.watcher_recipients - @recipients)
subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.custom_field_values} : #{issue.subject}"
body :issue => issue,
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
render_multipart('issue_add', body)
end
RE: Adding Custom Field Value to Subject in Notification Email - Added by Pierre Labrie over 10 years ago
This works in redmine 2.1 and 2.5. I used it to add a recipient to the mail list.
...
#{issue.custom_field_value(55)}
You take the id of the custom field in the url of the edition link: http://yourURL/custom_fields/55/edit
RE: Adding Custom Field Value to Subject in Notification Email - Added by Charles So over 9 years ago
What's the pre-requisite to using this variable? Do I have to instantiate any Class, if I want to use it somewhere else?
The reason is because we need this field value to replace the default Return-Path in email header.
RE: Adding Custom Field Value to Subject in Notification Email - Added by Federico Di Dio over 7 years ago
Pierre Labrie wrote:
You take the id of the custom field in the url of the edition link: http://yourURL/custom_fields/55/edit
I solved it this way:
issue.custom_value_for(CustomField.find_by_name('my-custom-field')).value
Also, make sure the method you are patching is actually used... I was very puzzled until I noticed a (long forgotten) plugin was overriding it. :)