Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,459,628
Community Members
 
Community Events
176
Community Groups

Using Jira cloud & script runner creating a calculated scripted field with error

I created 5 numeric custom fields for the HELPDESK project. These fields are not used for every ticket in the project, but when they are used all 5 are mandatory.

I have a 6th numeric custom field and using script runner I am trying to fill this field based on an equation from the 5 fields. 

I am using jira cloud so finding a solution on REST API. 

(I am not a developer)

 

Getting the below Error:

The scripted field ran successfully, but returned an invalid type. Please return a number    null

 

Code:

def input1CfId = 'customfield_10046'
def input2CfId = 'customfield_10047'
def input3CfId = 'customfield_10048'
def input4CfId = 'customfield_10049'
def input5CfId = 'customfield_10050'
def outputCfId = 'customfield_10060'
def projectKey = "HELPDESK"


def input1 = issue.fields[input1CfId] as Integer
def input2 = issue.fields[input2CfId] as Integer
def input3 = issue.fields[input3CfId] as Integer
def input4 = issue.fields[input4CfId] as Integer
def input5 = issue.fields[input5CfId] as Integer

if (input1 == null || input2 == null || input3 == null || input4 == null || input5 == null) {
logger.info("Calculation using ${input1}, ${input2}, ${input3}, ${input4}, and ${input5} was not possible")
return 0
}


def output = input1 * input2 * input3 * input4 * input5

if (output == (issue.fields[outputCfId] as Integer)) {
logger.info("already been updated")
return
}

put("/rest/api/2/issue/${issue.key}")
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output as Integer
]
])
.asString()

 

Can someone help me please?

1 answer

0 votes

The error message and the last line of your script combine to explain it.  The last line says "asString()", which converts the output to a string.  But you've set the field to be a number.

You just need to line up the types of output.

Sorry Nic, could you please help further? I am not familiar with coding.

You either need to target a text field for the output, or have your script return a number.  To do the second, remove the .asString as a start

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events