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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

looking for script in listenr

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

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you