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}"
}
Looking at this further, the script is updating the value correctly. However, due to the delay between the UI updating and the script completing, the change is not shown. After ~3 seconds we MAY receive a notification that the issue was updated with a link to refresh. We don't always get the notification though.
It looks like this issue is documented here: https://community.atlassian.com/t5/Jira-questions/JIRA-Cloud-ScriptRunner-Modifying-Issue-UI-is-not-updating/qaq-p/265834.
Hi,
First, you can clean your code and remove this block:
// 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
}
1. Because "issue" will never be null if "issue update" event is triggered.
2. In the listener configuration you can set on which projects you want it to run, that way you make sure your script runs only on the project you actually want (also reduce the call for listener for irrelevant projects).
Now... try your code this way:
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
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}"
}
} else {
return "Error retrieving issue ${NumVal}"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nir,
Thanks for the above. I had already set the project for the listener, but kept the check in the code just in case. I'll remove it.
Unfortunately it's still updating the URL based on the old NumField value. It seems like it's running the listener before it completes the update. Do I need to put in some kind of a wait? Or use a different event?
Thank you,
~Seth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nir,
Looking at this further, the script is updating the value correctly. However, due to the delay between the UI updating and the script completing, the change is not shown. After ~3 seconds we MAY receive a notification that the issue was updated with a link to refresh. We don't always get the notification though.
It looks like this issue is documented here: https://community.atlassian.com/t5/Jira-questions/JIRA-Cloud-ScriptRunner-Modifying-Issue-UI-is-not-updating/qaq-p/265834.
Thanks again for your help.
~Seth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.