Forums

Articles
Create
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

Map fields using Scriptrunner for Jira Cloud

Destri Weir
October 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
Bobby 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 Champions.
October 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
October 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 • Bobby Bailey likes this

Suggest an answer

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

Atlassian Community Events