Jira behaviour script for priority change

Sharadkumar Bangera November 18, 2020

Hello, 

 

How do i define a script in behavior 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"

 

Plz help with the script 

1 answer

0 votes
Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2020

Hi @Sharadkumar Bangera 

 

1) You can check the action as in https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html#_getaction and then execute the operation only for edits

2) Adding automated comment should be handled via listener or postfunction. Behaviour ideally updates the form fields in the screen and is stored in jira only when the user presses the click buttons to go forward. That said, you can set the comment field text to a certain text using behaviours (more like a suggestive text which user can even edit before save)

 

Refer to https://scriptrunner.adaptavist.com/5.5.8/jira/behaviours-overview.html for more instructions on the apis

Sharadkumar Bangera November 19, 2020

Thanks Fazila,

I m using Listener but what should be the scrpirt to add comment in listener when the priority is changed

Capture.PNG

Sharadkumar Bangera November 19, 2020

Hello,

 

I am Working in  Listener custom Script for my query whenever the Priorities change the Comment to be added in Jira "Priorities changed from Major to Minor".I am not good in scripting.

I m using below script but  it require a correction. Please help me where do i define the priority and comment "Priorities changed from Major to Minor".

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.model.ChangeGroup
import com.atlassian.jira.model.ChangeItem
import com.atlassian.jira.issue.history.ChangeItemBean

def commentManager = ComponentAccessor.getCommentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def issue = event.issue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = customFieldManager.getCustomFieldObjectByName("SomeDate")
def sd= cf.getValue(issue) as Date
def someDate = sd.format("yyyy-MM-dd")

String comment = "*Automatic comment:* SomeDate was updated to " + someDate

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Single User Picker CF"}

if (change) {
log.debug "Value changed from ${change.oldstring} to ${change.newstring}"

}

 

script.PNG

Suggest an answer

Log in or Sign up to answer