Project

General

Profile

Create Issue Relation

Added by Manuel Mai about 6 years ago

Hi,

I am trying to add this following functionality to Redmine via Custom Workflows:
If the user mentions another issue in the description or subject, a relation of the two issues is created automatically.

This is my code which is executed before saving:

Matchstring = ''
if description_changed?
  if self.description
    Matchstring = self.description
  end
end

if self.notes 
  Matchstring = Matchstring + self.notes
end

if Matchstring > ''
  Relations_Found = Matchstring.scan(/#[0-9]+/)
  Relations_Found.each do |r|
    rissue = Issue.find_by_id(r.gsub('#','').to_i)
    if rissue
      unless self.relations.include?(rissue)
          rel = IssueRelation.new(
           :issue_to => rissue,
           :issue_from => self,
           :relation_type => 'relates'
          )
          rel.save
      end
    end
  end
end

The problem is, the relation is only added to the issue currently being edited.
The related issue gets no journals entry, although the relation is shown in the issue info at the top.
Also it is possible to add a relation in the related issue to the first issue (which already should exist), so that there are two relations effectively - one in each of the issues.

Can you show me how to relate the two issues properly?

Thanks,
Manuel