I am writing a condition for script runner for JIRA that will look at the description of the issue and if the description has changed since the last change, it will evaluate false. Meaning, if the description was changed to trigger the issue updated event, it will evaluate false, or not fire.
Here is what I have, and it doesnt seem to be working.
if (issue.priority.name == 'P1' && issue.priority.name != originalIssue.priority && issue.issueType.name == 'Risk' && issue.status.name == 'Open' && issue.getDescription() == originalIssue.getDescription() && com.atlassian.jira.issue.attachment.Attachment == false ) return true
The rest of the code works, up until the description piece. Any advise or pointers are appreciated.
Community moderators have prevented the ability to post new answers.
Hi Alex,
So in a script listener in order to check if the update was cause by a change to a specific field, let's say description, you need something like
import com.atlassian.jira.issue.IssueFieldConstants def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == IssueFieldConstants.DESCRIPTION} if (change) { log.debug "Old value: ${change.oldstring} " log.debug "New value: ${change.newstring} " return true }
hope that helps.
regards, Thanos
It does, but could you explain to me the portion of code between def and the opening curly brace?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One of the objects are returning null, by using the safe navigation operator ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What the change actually does is checking the fields that changed during the issue updated event and if one of those is the description then ...
In case you want the JAVA API for the above, the event is of type IssueEvent, the getChangeLog is a GenericValue and the getRelated("ChildChangeItem") will return to you a List<GenericValue> and the IssueFieldConstants is order to get the id of the field description (you could use it.field = "description").
I missed the safe navigation operator before find (I updated it). Yes we use the null safe operator because
TheIssueEvent
object thrown as a result of an edit operation, may now return null from agetChangeLog()
call. This can occur when a user chooses to edit an issue but only leaves a comment and makes no other changes to the issue.
Hope that makes things more clear .
regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Much more clear.. Thank you very much.
Just need to figure out why it's throwing error for:
Cannot invoke method getBindings() on null object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Trying to get this section you sent me regarding the description changes to work before I add my other conditions back in, but this is continuously giving me the message:
Error
Cannot invoke method getBindings() on null object
import com.atlassian.jira.issue.IssueFieldConstants def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Description"} if (change) { log.debug "Old value: ${change.oldstring} " log.debug "New value: ${change.newstring} " return false }
Any additional thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is it getChangeLog() or getRelated("ChildChangeItem") that's causing the null object error?
Because I can assure you there is data in the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alex,
So first thing,
You want to use this in a listener or a post function and is it a custom or one of the provided ?(actually If you could paste a screenshot it would be great)
Which version of ScriptRunner and JIRA you use ?
In the script you sent you have find {it.field ==
"Description"
} where it should be
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == IssueFieldConstants.DESCRIPTION} //or def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "description"}
(even though this does not cause a Cannot invoke method getBindings() on null object)
cheers, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JIRA - 7.1.2
SR - 4.3.15
I am using the custom email listener.
I have tried it with both of the syntax you provided. I will take a couple screen shots and upload them to this thread.
Thanks for getting back to me.
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.
@Thanos Batagiannis _Adaptavist_
May I know how to check the same for a custom field using
event?.getChangeLog()?.getRelated("ChildChangeItem")?.find
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.