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 copy or create tags from custom fields values? #292

Closed ashrafalzyoud closed 1 year ago

ashrafalzyoud commented 1 year ago

272

if (custom_field_value(1) != custom_value_for(1).try(&:value)) && tracker_id == 4
    @issue.save_custom_field_values
    @issue.tag_list.add(CustomFieldEnumeration.where(:id=> custom_field_value(1).to_s,:custom_field_id => '1').first.to_s)
end

Not working if cfs[1] multiple value

AirTibu commented 1 year ago

Hi,

In case of multiple value field use this code:


CustomFieldEnumeration.where(id:custom_field_value(1).to_a,custom_field_id:'1').pluck(:name).each do |cfenum|
   @issue.tag_list << cfenum.to_s
end

I hope it helps!

ashrafalzyoud commented 1 year ago

Custom workflow error (Please contact an administrator) @AirTibu

AirTibu commented 1 year ago

Hi,

It's working fine for me. Use in before save section.

AirTibu commented 1 year ago

This code causing Custom workflow error (Please contact an administrator) if you try to use on NON multiple value field.

ashrafalzyoud commented 1 year ago

1-its work only if im choose multiple value, but maybe user choose one value or three value 2- cfs1 look like this somthing wronge 3333

AirTibu commented 1 year ago

Did you change the custom field id (1) to your custom field id?

ashrafalzyoud commented 1 year ago

IN MY CASE cfs id 8 4444

ashrafalzyoud commented 1 year ago

can u update the code the user can choose one value or multiple value

AirTibu commented 1 year ago

If the custom field type is Multiple values, then the code works if empty, if choosed only 1 option or choosed more option. I tested all the scenarios and it is working properly.

You can try with this code:


  CustomFieldEnumeration.where(id:custom_field_value(8).to_a,custom_field_id:'8').pluck(:name).each do |cfenum|
   self.tag_list.add(cfenum.to_s)
  end
ashrafalzyoud commented 1 year ago

its working thx for u alooooooooooooooooooot