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

How can I get related issues (only copy_from and copy_to) #290

Closed ngtquavn closed 1 year ago

ngtquavn commented 1 year ago

Hi all,

Please help me get list related issues only including copy_from and copy_to lists.

Thank you in advance.

AirTibu commented 1 year ago

Hi,

Use this code:

AFTER SAVE SECTION


@relations = "#".to_s +  IssueRelation.where("relation_type = ? AND (issue_to_id = ? OR issue_from_id = ?)","copied_to", self.id, self.id).pluck(:issue_from_id,:issue_to_id).uniq.compact.join(', #').squish.to_s

 self.custom_field_values = {'1' => @relations.to_s}
 self.save_custom_field_values

The first row collect the issues, with "#" prefix. The last 2 rows just add the result to a custom field, like this:

image

If you need only an array of issue ids, then use this code:


@relation_array = IssueRelation.where("relation_type = ? AND (issue_to_id = ? OR issue_from_id = ?)","copied_to", self.id, self.id).pluck(:issue_from_id,:issue_to_id)

I hope it helps!

ngtquavn commented 1 year ago

It works for me.

Thanks for your help.

AirTibu commented 1 year ago

It works for me.

Thanks for your help.

Your welcome! Don’t forget to close this issue!