The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy custom field value from text field to number field

Rose Cruz
Contributor
December 16, 2016

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

2 votes
April
Contributor
December 16, 2016

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 18, 2016

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.

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 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()
)