Grrovy script help

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 votes
Henning Tietgens Community Champion Feb 17, 2014

Try String.valueOf(time as int)

Thanks it works :)

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 Community Champion Feb 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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,011 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot