Hi! Im newbie in ScriptRunner so I need some help. I have to set moving numeric value from customfield1 to customfield2 on workflow transition. This value must be editable. Below I pass my code. This code is copiled okey, but I dont see any changes on issue.
Regards and Thanks!!!
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
//import com.atlassian.jira.issue.CustomFieldManager
//import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.customFieldManager
// the name of the custom field to update
def customFieldName = 'Cost'
def fundingFieldName = 'Funding'
def fundingField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
// the new value of the field
def newValue = customField.getValue(issue)
fundingField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fundingField), newValue), new DefaultIssueChangeHolder())
Hi @KatySpade
I have observed something in your code, i.e. if you intend to pass the value from one field to another, should you not be initialising two different fields?
If you observe your code, you appear to be initialising the same field twice, i.e.
def customFieldName = 'Cost'
def fundingFieldName = 'Funding'
def fundingField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
In both cases, you appear to be initialising the Cost field.
Try to modify your code slightly to:-
def customFieldName = 'Cost'
def fundingFieldName = 'Funding'
def fundingField = customFieldManager.getCustomFieldObjectsByName(fundingFieldName).first()
def customField = customFieldManager.getCustomFieldObjectsByName(customFieldName).first()
Also, try to use
issue.setCustomFieldValue(fundingField, issue.getCustomFieldValue(customField))
And see if you can get the expected result.
So your full updated code should be:-
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def customFieldName = 'Cost'
def fundingFieldName = 'Funding'
def fundingField = customFieldManager.getCustomFieldObjectsByName(fundingFieldName).first()
def customField = customFieldManager.getCustomFieldObjectsByName(customFieldName).first()
issue.setCustomFieldValue(fundingField, issue.getCustomFieldValue(customField))
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.