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

correct script #269

Closed ashrafalzyoud closed 2 years ago

ashrafalzyoud commented 2 years ago

if @issue_custom_field_value(1).changed? what the correct code plz

AirTibu commented 2 years ago

Hi,

Add to BEFORE SAVE:


# only valid in before_save scripts
def custom_value_changed?(cf)
    custom_field_value(cf.id) != custom_value_for(cf.id).try(&:value)
end

And call the this function with:


if custom_value_changed?(1) 
# do this...
end
ashrafalzyoud commented 2 years ago

can u plz participant with this ticket

267

ashrafalzyoud commented 2 years ago

i made some changes cf_id

# only valid in before_save scripts
def custom_value_changed?(cf_id)
   custom_field_value(cf_id) != custom_value_for(cf_id).try(&:value)
end

can this function work after _save

if custom_value_changed?(1) 
# do this...
end

im try this code and make changes in value cf_1 but the function not work also

ashrafalzyoud commented 2 years ago

@AirTibu

AirTibu commented 2 years ago

Hi,

Use with @issue:


def custom_value_changed?(cf_id)
    @issue.custom_field_value(cf_id) != @issue.custom_value_for(cf_id).try(&:value)
end

This can work in after_save only you store the custom field value in before save (not tested, just an idea):


BEFORE  SAVE:

@original_value = @issue.custom_value_for(cf_id).try(&:value)

AFTER SAVE:

if @issue.custom_field_value(cf_id) != @original_value && !@original_value.nil?
# do your code here
end

I hope it helps!