Copy custom field value from text field to number field

Using ScriptRunner "Copy custom field values" function, I'm trying to copy values from a text field to a number field. I've confirmed that all issues in my filter results have a numeric value in the text field, but the script does not modify any issues. Will this ever be supported?

2 answers

This widget could not be displayed.

If I remember right, you have to cast as double. Did you try that?

Er, I should add that while I don't think this is directly supported in Scriptrunner, I've gotten around this before by making a scripted field that gets the value from the text field as a number (return (something) as Double), and then you can use the built in function to copy over the data.

Seems like a good thing to try...

Probably text to number is not supported, but as April said you can create a (Number) script field which gets the text value, and then use the built-in script to copy from the script field to the number field.

This widget could not be displayed.
Vasiliy Zverev Community Champion Dec 17, 2016

Here is code for script postfunction provided by ScriptRunner plugin

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue

import java.text.DecimalFormat

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
DecimalFormat decimalFormat = new DecimalFormat();

issue.setCustomFieldValue(
        customFieldManager.getCustomFieldObjectByName("number field name")
        , decimalFormat.parse ( (String) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("text field name"))).doubleValue()
)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

121 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you