How to modify script listener to fire only when specific custom field is modified?

Bryan Karsh
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.
November 19, 2014

Hi guys,

I created a script listener that works great – it updates a customer field  (field B) based on values from another field (field A).

Is there a way (via condition, etc) to only fire the listener if field A is modified? Right now my script runs whenever anything is edited for a specific project, and inside the script it updates field B based on field A values. Like so:

 

def customFieldManager = ComponentAccessor.getCustomFieldManager()
        def optionsManager = ComponentAccessor.getOptionsManager()

        MutableIssue myIssue = event.issue as MutableIssue

        def classification = customFieldManager.getCustomFieldObjects(myIssue).find { it.name == "Classification" }
        def supportModel = customFieldManager.getCustomFieldObjects(myIssue).find { it.name == "Support Model" }

        def classValue = myIssue.getCustomFieldValue(classification).join(" - ")


        def supportModelValue = map[classValue]
        try {
            def fieldConfig = supportModel.getRelevantConfig(myIssue)

            def option = optionsManager.getOptions(fieldConfig).find {it.value == supportModelValue}



            IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
            supportModel.updateValue(null, myIssue, new ModifiedValue("", option),changeHolder);

 

 

Thanks. And if you are curious, Field A is a multi-level cascading field. I get the list of its values for each level, and join it to make a string – that string is a key in a map where the corresponding value is the name of an option in field B.

1 answer

1 vote
Nic Brough (Adaptavist) November 19, 2014

No, a listener responds to all events.

Without messing around with core functionality, the best you can do is put an "if" at the beginning of the listener to check if the event says the field has changed.

JamieA
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.
November 23, 2014

No relation to Nic Brough I take it? ;-)

Nic Brough -Adaptavist-
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 23, 2014

Actually, yes, we have a great-grandfather in common. She's does technical author type work sometimes and I've helped her out with Atlassian docs a couple of times.

JamieA
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.
November 24, 2014

Hopefully she won't be as prodigious on AAC as you, although maybe it runs in the family!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events