Hi,
I want to copy a custom field (numeric) value to another custom field.
I'm using Script-Runner addon to call a custom inline script on post function for a transition that fires on every issue update (transitions: Any status -> Itself).
I can't seem to find the way to update a custom field.
So for example:
"Custom field 1" = 7.5
"Custom field 2" = 3
When event is fired through workflow, Custom field 2 should also become 7.5.
For all things I've tried, f.e. setCustomField, I run into methods not existing, etc.
JIRA version: 7.0.0
ScriptRunner version: 4.2.0.2
Thanks.
Community moderators have prevented the ability to post new answers.
Hi Dennis,
I have been told that the setCustomFieldValue is no longer working and you have to use something along the lines of Thanos answer in here: https://answers.atlassian.com/questions/33158582.
Hope this helps.
Hi Dennis,
please provide which versions you have. Both JIRA and Script-Runner.
This would be an example.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def cfManager = ComponentAccessor.getCustomFieldManager() def cfCond = cfManager.getCustomFieldObject(11200L) // source field id def value = cfCond.getValue(currentIssueObject).toString() def cfITExec = cfManager.getCustomFieldObject(11310L) // target field id currentIssueObject.setCustomFieldValue(cfITExec, value);
But also you could use a standard "copy value" workflow post-function in your workflow.
Hope this helps.
Best Regards,
Mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mario, thanks for answering. I have updated my start post with versioning. With your script I am running into f.e. currentIssueObject being undefined. That said, with the ID's, is it the customfield ID followed by an "L"? Or does that ID come frome some place else? The copy function doesn't apply to Custom Fields does it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dennis in the code that Mario posted you can use def targetField = customFieldManager.getCustomFieldObjectByName("CF name") def cfValue = issue.getCustomFieldValue(targetField)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for replying. Didn't find that working for me. Still causing errors around methods not existing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dennis, could you please provide your error stack trace?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I now have the following code. I managed to get it working a bit earlier for a static value, but the script I have now does not work (but does not throw error in script input editor. Please note that the cfHoursToBill field is a scripted field which may be of importance: import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def cfManager = ComponentAccessor.getCustomFieldManager() // Get value of already billed hours def cfAlreadyBilled = cfManager.getCustomFieldObjectByName("Uren gefactureerd") def cfAlreadyBilledValue = (double) cfAlreadyBilled.getValue(issue) // Get value of additional hours to be build def cfHoursToBill = cfManager.getCustomFieldObjectByName("Uren te factureren") def cfHoursToBillValue = (double) cfHoursToBill.getValue(issue) // Set value of already billed + to be billed as new value for already billed hours def newValue = cfHoursToBillValue + cfAlreadyBilledValue issue.setCustomFieldValue(cfAlreadyBilled, newValue);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.