I'm writing a listener that will take a value in a custom field, append that value to a hardcoded string to create a URL, and update a different custom field.
When the listener fires, it's taking the value of the custom field before update and building the URL based on that value.
For instance, if the custom field has value 555 and you update it to 444, the URL created is
https://support/CSIssue_View.asp?IssueNbr=555. I want it to create https://support/CSIssue_View.asp?IssueNbr=444.
How do you get the listener to wait until the issue is updated before firing the listener?
Thank you,
Settings:
On these events = Issue Updated
Code:
def projectKey = 'TEM'
def issueKey = issue.key
def NumField = 'customfield_10726'
def UrlField = 'customfield_10705'
def result = get("/rest/api/2/issue/${issueKey}?fields=${NumField}")
.header('Content-Type', 'application/json')
.asObject(Map)
def NumVal
if (result.status == 200)
{
NumVal = result.body.fields[NumField] as Integer
}
else
{
return "Error retrieving issue ${NumVal}"
}
// make sure we have the data and we're in the correct project
if (issue == null || issue.fields.project.key != projectKey)
{
logger.info("Wrong Project ${issue.fields.project.key}")
return
}
def post_result = put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
customfield_10705: 'https://support/CSIssue_View.asp?IssueNbr=' + NumVal
]
])
.asString()
if (post_result.status == 204) {
return 'Success'
} else {
return "${post_result.status}: ${post_result.body}"
}