Grrovy script help

Sanu Soman
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 Leaders.
February 17, 2014

Hi All,

I'm looking for to add some random numbers to a jira custom field ("Actual time") by below groovy script as part of workflow transition. Everything works fine but couldn't remove the decimal part from below number, ie, here I need the custom field value as "1". Please suggest how its possible?

def time = 1.5166666667

IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager();

def MeD =cfm.getCustomFieldObjectByName("Actual time");
issue.setCustomFieldValue(MeD, String.valueOf(time));

1 answer

1 accepted

1 vote
Answer accepted
Henning Tietgens
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 Leaders.
February 17, 2014

Try String.valueOf(time as int)

Sanu Soman
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 Leaders.
February 17, 2014

Thanks it works :)

Sanu Soman
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 Leaders.
February 17, 2014

Also, currently the custom field "time" is free text field. Which all changes needs to be done in code level for changing the field type to number field. Now getting below error,

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double

Please suggest.

Henning Tietgens
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 Leaders.
February 17, 2014

Make sure you set a Double as custom field value. You can chain "as" commands.

issue.setCustomFieldValue(MeD, (time as int) as Double);

Suggest an answer

Log in or Sign up to answer