redmine_custom_workflows icon indicating copy to clipboard operation
redmine_custom_workflows copied to clipboard

Relate issues when they have the same subject

Open frankz96 opened this issue 2 years ago • 1 comments

Here is what i want: when i creat a new issue or other operate, if two or more issues have same "Subject", them relate them in "Related issues". Thank you very much if anyone can helps.

frankz96 avatar Sep 22 '22 07:09 frankz96

@picman Hi, thanks for your revision, but the "help wanted" label is not correct😅

frankz96 avatar Sep 26 '22 02:09 frankz96

Hi,

Use this code:

AFTER SAVE SECTION:


same_subject = Issue.where("subject = ?",self.subject).pluck(:id)

same_subject.each do |issueid|
    relation = IssueRelation.new :issue_from => self, :issue_to => issueid,:relation_type => IssueRelation::TYPE_RELATES
    relation.save
end

I hope it helps!

AirTibu avatar Dec 21 '22 19:12 AirTibu

Hi,

Use this code:

AFTER SAVE SECTION:


same_subject = Issue.where("subject = ?",self.subject).pluck(:id)

same_subject.each do |issueid|
    relation = IssueRelation.new :issue_from => self, :issue_to => issueid,:relation_type => IssueRelation::TYPE_RELATES
    relation.save
end

I hope it helps!

@AirTibu Hi, thank you very much for your help. But I tried your code, it didn't work. I create a new issue with duplicate subject. Here is what i found in log file:

Custom workflow exception: Issue(#47344935497480) expected, got 10762 which is an instance of Integer(#47344902929580)

I found the issue with id 10762 is the duplicate subject issue. Could you fix this problem?

frankz96 avatar Dec 22 '22 07:12 frankz96

Hi,

You are right, small correction is needed, use this code:

same_subject = Issue.where("subject = ?",self.subject).pluck(:id)


same_subject.each do |issueid|
    relation = IssueRelation.new :issue_from => self, :issue_to => Issue.find(issueid),:relation_type => IssueRelation::TYPE_RELATES
    relation.save
end

I hope it helps!

AirTibu avatar Dec 31 '22 14:12 AirTibu

Hi,

You are right, small correction is needed, use this code:

same_subject = Issue.where("subject = ?",self.subject).pluck(:id)


same_subject.each do |issueid|
    relation = IssueRelation.new :issue_from => self, :issue_to => Issue.find(issueid),:relation_type => IssueRelation::TYPE_RELATES
    relation.save
end

I hope it helps!

Thank you so much! It worked perfectly.

frankz96 avatar Jan 05 '23 07:01 frankz96