looking for script in listenr

Sharadkumar Bangera November 19, 2020

How do i define a script in Listener - field,

1)which should be executed only during the EDIT screen,

2)if priority is changed from major to minor, it should add comment in ticket " Priority changed from major to minor"

 

Please provide the script if there is any , i already refer various google answer but it failed when i implemnted it

Script which i used and it is incomplete, kindly help me with above requirement

I used Listener- Field

import com.atlassian.jira.component.ComponentAccessor
issue.priority?.name == 'Blocker'
issue.summary == 'Priority is changed'

 

Capture.PNG

 

1 answer

0 votes
mogavenasan
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.
January 4, 2021

Hi @Sharadkumar Bangera,

1)which should be executed only during the EDIT screen,

Script Listener is designed to work based on the Events - that means the Listener would not know if the action was done on the screen or inline edit or REST API calls.

2)if priority is changed from major to minor, it should add comment in ticket " Priority changed from major to minor"

  1. The Event that you have configured is correct - Priority Changed.
  2. You will need a block of code to check if the old Priority is Major and the new Priority is Minor.
    def field = event.getChangeLog().getRelated('ChildChangeItem').find{it.field == "Priority"};
    
    def old_field_value = field.oldstring;
    
    def new_field_value = field.newstring;

    if (old_field_value == "Major" && new_field_value == "Minor") {
    do something here
    }
  3. And then, you will need a few lines of code to add the comment.
    import com.atlassian.jira.component.ComponentAccessor 

    def commentManager = ComponentAccessor.getCommentManager()
    def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

    if (old_field_value == "Major" && new_field_value == "Minor") {
    commentManager.create(
    issue,
    user,
    "Priority changed from Major to Minor",
    false)
    }

Disclaimer: I have not tested the code above. These are all from a very old script that I have before.

Thanks,
Moga

Suggest an answer

Log in or Sign up to answer