How add condition in Listener ?

Alex
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.
October 12, 2023

Hi, everyone!

I have code in a listener and I want to add a condition so that this listener will only fire if the myCF field has been changed.

And make it work for the Сurrent task and not just for: def issueKey = "RDY-12917" :

 

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor

def customFieldPOactive = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_18429")
def issueManager = ComponentAccessor.getIssueManager()
def issueObject = issueManager.getIssueObject("${issueKey}")
def cfName = "Software(active)"
def cfPOactiv = issueObject.getCustomFieldValue("${cfName}").findAll().join("")

def regStringPOactive = (cfPOactiv =~ /RFA-\d\w+/).findAll().join("") // key for object "Software(active)": RFA-195553
def attrObjLineOfProduct = Assets.getByKey("${regStringPOactive}").getAttributeValues('Line of Product')
def regStringLineOfProduct = (attrObjLineOfProduct =~ /\d\w+/).findAll().join("")
def keyAttrLineOfProduct = 'RFA-'+ regStringLineOfProduct
def attrNameLineOfProduct = Assets.getByKey("${keyAttrLineOfProduct}")
def AttrValueLineOfProduct = (attrNameLineOfProduct =~ /\s*\(RFA-\d+\)/).findAll().join("") // value in attribute 'Line of Product' (in object - "Software(active)")

//<---------------------------------- Add value name in CF "Line of Product" --------------------------------------------------------------------------->

issueObject.update {
setCustomFieldValue('Line of Product') {
set(AttrValueLineOfProduct)

}

}

//<---------------------------------- Add value name in CF "Vendor(active)" ----------------------------------------------------------------------------->

def attrObjVendor = Assets.getByKey("${regStringPOactive}").getAttributeValues('Developer')
def regStringVendor = (attrObjVendor =~ /\d\w+/).findAll().join("")
def keyAttrVendor = 'RFA-'+ regStringVendor
def attrNameVendor = Assets.getByKey("${keyAttrVendor}")
def AttrValueVendor = (attrNameVendor =~ /\s*\(RFA-\d+\)/).findAll().join("") // // value in attribute 'Vendor(active)' (in object - "Software(active)")

issueObject.update {
setCustomFieldValue('Vendor(active)') {
set(AttrValueVendor)

}

}

Any help is important!

Thank you

1 answer

1 accepted

1 vote
Answer accepted
Miklos Tix October 12, 2023

Hi @Alex

you can use the following:

 

Issue issue = event.issue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field=="YOURCUSTOMFIELD"}
if (change){
}
Let me know if you cannot manage it.
Alex
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.
October 13, 2023

@Miklos Tix 
Hello! Thank you very much for your work! It worked great! :)

Suggest an answer

Log in or Sign up to answer