You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello community !
My script that should be replacing commas with '.' in a custom field, but it is not doing this in tickets.
Custom field named "global cost" is a "number field" type which is calculated in a script listener.
I need to know why my script listener is returning a value containing a comma, although in the script I use a comma to point function : .replace(",", ".")
Also I have tested it in a script console, and it gives me the correct result (decimal value with a point and not a comma).
On a ticket, listener does not fill correctly decimal value since point is replaced by a comma. Therefore, an error message "invalid number" blocks ticket creation. (see below).
Here is the update value line :
globalcostsField.updateValue(null, parent, new ModifiedValue(parent.getCustomFieldValue(globalcostsField), Double.parseDouble(String.format("%.2f", count * 0.65).replace(",", "."))), new DefaultIssueChangeHolder());
----------------------------------------------------------------
Whole script :
//Custom listener
//Projects: DE,FR,IT,UK,TEST
//Events: Issue Updated
//Update global cost of a user request according to the sum of subtasks effort
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
String tshirtField = "customfield_10207";
String costsField = "customfield_10208";
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
CustomField serviceType = cfm.getCustomFieldObject("customfield_10706");
CustomField globalcostsField = cfm.getCustomFieldObject("customfield_15402");
IssueManager im = ComponentAccessor.getIssueManager();
if (event.getIssue().getIssueTypeId() == "22") {
Issue parent = event.getIssue().getParentObject();
Double count = 0;
Double cost = 0;
for (Issue i : parent.getSubTaskObjects()) {
cost = i.getCustomFieldValue(cfm.getCustomFieldObject(costsField)) != null ? (Double) i.getCustomFieldValue(cfm.getCustomFieldObject(costsField)) : 0;
if (i.getCustomFieldValue(cfm.getCustomFieldObject(tshirtField)) != null)
{
switch (i.getCustomFieldValue(cfm.getCustomFieldObject(tshirtField)).toString().substring(0,2).replace(" ", "")) {
case "XS":
count += Math.max(2, cost);
break;
case "S":
count += Math.max(4, cost);
break;
case "M":
count += Math.max(9, cost);
break;
case "L":
count += Math.max(19, cost);
break;
case "XL":
count += Math.max(30, cost);
break;
}
}
else
{
count += cost;
}
}
if ((count * 0.65) > (Double)(parent.getCustomFieldValue(globalcostsField).toString() != "null" ? parent.getCustomFieldValue(globalcostsField) : 0)) {
globalcostsField.updateValue(null, parent, new ModifiedValue(parent.getCustomFieldValue(globalcostsField), Double.parseDouble(String.format("%.2f", count * 0.65).replace(",", "."))), new DefaultIssueChangeHolder());
}
}
------------------------------------------------------
-----------------------------------------------------------------
Jira version : JIRA 7.1.7
ScriptRunner version : 4.3.1
-------------------------------------------------------------------
Thanks a lot !!!
You cannot put formatting into a numeric field. The field accepts whatever you have for a decimal point and stores it as a number, not a string.
It is your language settings that determine what you see when Jira renders a number.
Thanks for your quick feedback.
In fact, when I open this issue in "view" mode, I can see global cost is : "5.85". But if I open it in "editing" mode, I can see "5,85".
So when I try to edit another field ih the ticket (I do not modify this one since it is automatically filled), I am blocked with this error message.
Language settings is "english", I don't see why it is an issue.
I have found a Workaround by hiding this field in "edit" view. So I hope my user will be satisfied with that !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're missing the point - your code is trying to use a separator that is invalid. You simply don't need to try to set it, just pass the number into the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you be more specific ?
I have tried not to replace "," to ".", by replacing former update line by this line :
globalcostsField.updateValue(null, parent, new ModifiedValue(parent.getCustomFieldValue(globalcostsField), Double.parseDouble(String.format("%.2f", count * 0.65))), new DefaultIssueChangeHolder());
I have same error.
Please let me know your code suggestion.
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.