anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
182 stars 72 forks source link

Relate issues when they have the same subject #282

Closed frankz96 closed 1 year ago

frankz96 commented 2 years ago

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 commented 2 years ago

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

AirTibu commented 1 year ago

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!

frankz96 commented 1 year ago

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?

AirTibu commented 1 year ago

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!

frankz96 commented 1 year ago

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.