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()
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.