Scriptrunner on Jira Cloud that calculates fields from String values to Int

Hello! I've been struggling with a Calculated field in Scriptrunner for Jira Cloud I'm trying to figure out.

I have three separate Custom field options that all contain at least one number at the start of each option such as "1. User doesn't care" and "2. User might be annoyed".

I want to grab the values from each Custom Field, then strip the number from the option, and calculate a sum of the values, adding the summed value to a Number Custom field.

For some reason when i output the below code to a Custom Field with Text field, I get the body with value, id and so forth even though I pick issue.field[refToCf].value.

Even if I cast them as String or int I can't get it to work.

Any help is greatly appreciated! Thanks!

def input1CfId = 'customfield_10048'//'customfield_10046' //Bug Priority string
def input2CfId = 'customfield_10046' //Likelihood string
def input3CfId = 'customfield_10047' //Bug type string
def outputCfId1 = 'customfield_10056' //User pain Integer

def bugPriority = issue.fields[input1CfId] as String
def likelihood = issue.fields[input2CfId] as String
def bugType = issue.fields[input3CfId] as String

def output = bugPriority[0..0]+likelihood[0..0]+bugType[0..0] as Integer

put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId1): output
]
])
.asString()

Any ideas? Its kind of driving my crazy.

1 answer

So I figured it out, it had to be

def bugPriority = issue.fields[input1CfId]['value'] as String

instead of

def bugPriority = issue.fields[input1CfId] as String

to return the value only instead of the whole body containg value, self and id

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 ...

2,811 views 11 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