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

Set parent issue custom field to a certain value if subtask's custom field is set to another value and subtask is closed #251

Closed lublasco closed 2 years ago

lublasco commented 2 years ago

Parent issue custom field id=1 Parent issue custom field 1 values= Value11, Value12

Subtask custom field id= 2 Subtask custom field values= Value21, Value22

Hi, I've achieved one part of the requisite (to close parent task if subtask is closed), but need help to set the parent issue custom field to Value11 if the subtask's custom field is set to Value21.

-- before save --

if @issue.status_id_changed? && (tracker_id == 17)
@issue.status_id = 5
@checkfield = subject.present? ? (status_id_changed?) : false
end

--after save --

if @checkfield
        @issue.parent.update({:status_id=>7})
    end  

It would be great if anyone could complete the above code. Thank you very much in advance.

AirTibu commented 2 years ago

Hi,

Use this code in AFTER SAVE:


if !parent.nil? && custom_field_value(180).to_s == "Value11"

   self.parent.custom_field_values = { 154 => "Value21"}

   self.parent.save_custom_field_values
end

I hope it helps!

lublasco commented 2 years ago

Awesome @AirTibu , worked like a charm! Thank you very much for your quick help :)

frankz96 commented 2 years ago

@AirTibu Hi!

I have one question, why there is 154 at second row?

frankz96 commented 2 years ago

@AirTibu I want to change a custom field (user) based on issue status, but it doesn't work, here is my code:

if @issue.status_id == 2
  @issue.custom_field_value_2 = @assigned_to
end

i tried to change the code to this:

if @issue.status_id == 2 @issue.custom_field_values = { 2 => @issue.assigned_to} end

it still not work.

could you help me?

AirTibu commented 2 years ago

@AirTibu Hi!

I have one question, why there is 154 at second row?

Hi,

180 is my custom field ID. You should change to 2 (according to your first mail, this is the subtask custom field)

154 is also my custom field ID, you should change to 1

AirTibu commented 2 years ago

@AirTibu I want to change a custom field (user) based on issue status, but it doesn't work, here is my code:

if @issue.status_id == 2
  @issue.custom_field_value_2 = @assigned_to
end

i tried to change the code to this:

if @issue.status_id == 2 @issue.custom_field_values = { 2 => @issue.assigned_to} end

it still not work.

could you help me?

Hi,

Use this code in AFTER SAVE:


if self.status_id=='2'

     self.custom_field_values = {'2' => assigned_to_id.to_s}

     self.save_custom_field_values

end

I hope it helps!

frankz96 commented 2 years ago

@AirTibu I want to change a custom field (user) based on issue status, but it doesn't work, here is my code:

if @issue.status_id == 2
  @issue.custom_field_value_2 = @assigned_to
end

i tried to change the code to this: if @issue.status_id == 2 @issue.custom_field_values = { 2 => @issue.assigned_to} end it still not work. could you help me?

Hi,

Use this code in AFTER SAVE:


if self.status_id=='2'

     self.custom_field_values = {'2' => assigned_to_id.to_s}

     self.save_custom_field_values

end

I hope it helps!

thanks a lot!

It doesn't work at first, i tried to change some parts and put following code in BEFORE SAVE:

if @issue.status_id==2 @issue.custom_field_values = {'2' => assigned_to_id.to_s} end

and it perfectly work.

thanks again!

AirTibu commented 2 years ago

Hi,

Yes, there was indeed a flaw in it. The status ID should not have been put as an apostrophe. The self and @issue mean the same thing, it can't be a mistake.

I'm sorry, I wrote my last message half asleep.

If you want to update a custom field in the AFTER SAVE section, you only need to save the custom field:

     self.save_custom_field_values

Would you close the issue if the problem is resolved? Thanks!