Custom script post-function does not work


I want to set a customfield value based on another's field selection. I will copy the first letter of the selcted option of the customfield "Time to Benefit" (it's a number). Further, i want to calculate with this number later one, that's why I change the string to a double.

def cf = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Time to Benefit").substring(0, 1).toDouble());
def cd = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Value"));
issue.setCustomFieldValue(cd, cf);



3 answers

1 accepted


now it works:

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customfield");
def cd = DOuble.valueOf((issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Value"))).getValue().substring(0, 1));
issue.setCustomFieldValue(cf, cd);

 Thank you very much for your help!!


Best regards,


Hi Louisa,

Few things are not right here.

def cf = Double.valueOf(((Option) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Time to Benefit"))).getValue().substring(0, 1));

Above line gives you the double value of the first letter of field "Time to Benifit"

def cd = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Value"));

This gives you the value of field "Value"

issue.setCustomFieldValue(cd, cf);

This doesnt work as the setCustomFieldValue takes two arguments, CustomField and value for customfield, and in your case both arguments are values to some fields.



Hi Vijay,

Thank you for your fast response!

The following code works:

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customfield");
issue.setCustomFieldValue(cf, 3 as Double);

 However, your first suggested line to get the first character of the selected option and convert it into an double does not work. Do you see any mistakes i made?

That's how I implemented your code:

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customfield");
def cd = Double.valueOf(((Option) issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Value"))).getValue().substring(0, 1));
issue.setCustomFieldValue(cf, cd);


Best Regards,


Good to know it works. Sorry i missed the notification and saw your reply now.

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,190 views 13 19
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