Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

Map fields using Scriptrunner for Jira Cloud

Destri Weir
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Oct 27, 2023

I am trying to populate values in a custom numeric field Contract Terms (field ID 10262) based on a selection in a custom single-select drop-down list field Supplier (field ID 10132) on and issue create event. These fields are on a Jira Service Manager screen. I'm using the following script that runs without error, but it does not populate the Contract Terms field. 

I need help troubleshooting why the script isn't populating the Contract Terms field. 

import groovy.json.JsonOutput


def issue = event.issue // Get the issue object from the event
def issueKey = issue.key // Get the issue key from the issue object


def supplierFieldId = "customfield_10132" // Replace with the correct custom field ID
def contractTermsFieldId = "customfield_10262" // Replace with the correct custom field ID


def supplierFieldValue = event.issue.fields[supplierFieldId]


def contractMap = [
"British Gas (BG)": -35,
"E-ON Next": -20,
"Scottish Power": -30,

]


def newValue = contractMap[supplierFieldValue]
def updateData = [
fields: [(contractTermsFieldId): newValue]
]


def updateJson = JsonOutput.toJson(updateData)


def response = put("/rest/api/3/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body(updateJson)
.asString()

 

1 answer

1 accepted

2 votes
Answer accepted
Robert Bailey
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.
Oct 27, 2023

Hi @Destri Weir , 

 

The issue you have is with this line: 

def supplierFieldValue = event.issue.fields[supplierFieldId]

You are getting all the custom field information, not just the value. If you change this to:

def supplierFieldValue = event.issue.fields[supplierFieldId].value.toString()


Your listener should work. Let me know if this works for you!

Kind regards, 

Bobby

Destri Weir
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Oct 30, 2023

Bobby,

 

It worked like a charm! Thank you so much for your help, and for explaining why it wasn't working before. I appreciate your response so much. 

 

Thanks again, 

 

Destri

Like Robert Bailey likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events