Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script Runner condition for issue description

Alex Lorsung February 9, 2017

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.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Thanos Batagiannis _Adaptavist_
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 Leaders.
February 9, 2017

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

Alex Lorsung February 9, 2017

It does, but could you explain to me the portion of code between def and the opening curly brace?

Alex Lorsung February 9, 2017

One of the objects are returning null, by using the safe navigation operator ?

Thanos Batagiannis _Adaptavist_
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 Leaders.
February 9, 2017

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 

The IssueEvent object thrown as a result of an edit operation, may now return null from a getChangeLog() 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,

Alex Lorsung February 9, 2017

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

Alex Lorsung February 9, 2017

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?

Alex Lorsung February 9, 2017

is it getChangeLog() or getRelated("ChildChangeItem") that's causing the null object error?

 

Because I can assure you there is data in the field.

Thanos Batagiannis _Adaptavist_
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 Leaders.
February 9, 2017

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

Alex Lorsung February 10, 2017

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.

 

Alex Lorsung February 10, 2017

SR_1.pngSR_2.PNG

0 votes
Aishwarya Rajan March 15, 2018

@Thanos Batagiannis _Adaptavist_  

May I know how to check the same for a custom field using 

event?.getChangeLog()?.getRelated("ChildChangeItem")?.find

TAGS
AUG Leaders

Atlassian Community Events