Project

General

Profile

Update Custom Values Problem

Added by RedminePro Yang over 15 years ago

I am trying to add a new feature to change custom field value for list of issues. How can I update the issue.custom_values with some of custom fields value. I did it like this, but not work. Someone help me.

def update_some_custom_values(some_custom_values)
transaction do
  if  some_custom_values
        some_custom_values.each {|c|
          next if (c.value.nil? || c.value.blank?)
          self.custom_values.each {|sc|
           if(c.custom_field.id==sc.custom_field.id)
             puts c.value              # Result: "December" 
             puts sc.value              # Result: "November" 
             sc=c                           # I also try:  sc.value=sc.value 
             puts sc.value             # Result: "December" 
           end
          }
        }    

          self.custom_values.each {|sc| 
            puts sc.value              # Result: "November"  Why become November again?
          }
      end
     if save
        # Manually update project_id on related time entries
        TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
      else
        rollback_db_transaction
        return false
      end
    end
    return true
end


Replies (1)

RE: Update Custom Values Problem - Added by RedminePro Yang over 15 years ago

Problem solved.

 if  custom_values
        self.custom_values = self.custom_values.clone.collect {|v| 
          newValue =v.clone
          custom_values.each {|c|
           next if (c.value.nil? || c.value.blank?)
           if(c.custom_field.id==v.custom_field.id)
             newValue=c
           end
           }
          newValue}
      end

    (1-1/1)