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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,462,016
Community Members
 
Community Events
176
Community Groups

To check the and update field value based on the value of another field by using listenters

We have a requirement to check the and update field value based on the value of another field, Eg.- if A is system field and B is custom field we are looking to capture the corresponding value and check for all the jira issues with the same field value of A where field value for B is empty and need to update the value of B for all the impacted stories with same value field of A, by using listeners during issue created and updated events..Can you please help us to achieve this?

4 answers

0 votes

It usually helps to know which line exactly the syntax error is on. And usually, the error will have some details that can help suggest a solution.

But when I copy your snippet, I can see a few errors:

1) you are using the wrong type of quotes around "Fix Version". 

2) there is an extra dot after the parens on that same line.

And if you're using the script I supplied in the other thread and just adding the snippet above. Then you're also possibly missing some imports.

But I agree with @Vamsi Kandala  if you don't have enough coding experience to be able to resolve simple syntax errors, a scripted listener is probably not for you. An automation rule might be simpler to maintain.

Resolved the syntax errors  and  the script https://community.atlassian.com/t5/Adaptavist-questions/Need-help-with-setting-up-a-listener-to-verify-a-field-values/qaq-p/2218299?utm_campaign=accept_as_solution_reminder&utm_content=view-answer&utm_medium=email&utm_source=atlcomm#M10495 is running fine without any issues.

 

Trying to add error handler to the above  set the request number field to null if there is any update on the fix versions field and tried to the below code..

if (event.eventTypeId == EventType.ISSUE_UPDATED_ID) {

    def listOfFields = ['Fix Version', customFieldName]

    def changeItems = ComponentAccessor.changeHistoryManager.getChangeHistoryById(event.changeLog.id as Long).changeItemBeans

     log.info "Issue updated detected. Changed fields: ${changeItems*.field}"

     if (!changeItems.any { it.field in listOfFields }) {

        //don't run the listener if the user changed an unrelated field.

        log.warn "$listOfFields were not found in the list of changed fields."

        return null

    }

      if ( changeItems.any { it.field == ‘Fix Version’ }).

    {

        issue.setCustomFieldValue(customField, null)

          customField.updateValue(null, issue, new ModifiedValue(customFieldValue, null), new DefaultIssueChangeHolder())

    }

}

Tried both customField.updateValu and issue.setCustomfield methods, but getting the syntax errors.

Please help.....

0 votes

Hi @Ramesh Penuballi

I suggest that using automation rules will be simpler than using the listeners.  Please try considering this.

Thanks,
Vamsi

Resolved the syntax errors  and  the script https://community.atlassian.com/t5/Adaptavist-questions/Need-help-with-setting-up-a-listener-to-verify-a-field-values/qaq-p/2218299?utm_campaign=accept_as_solution_reminder&utm_content=view-answer&utm_medium=email&utm_source=atlcomm#M10495 is running fine without any issues.

 Trying to add error handler to the above  set the request number field to null if there is any update on the fix versions field and tried to the below code..

if (event.eventTypeId == EventType.ISSUE_UPDATED_ID) {

    def listOfFields = ['Fix Version', customFieldName]

    def changeItems = ComponentAccessor.changeHistoryManager.getChangeHistoryById(event.changeLog.id as Long).changeItemBeans

     log.info "Issue updated detected. Changed fields: ${changeItems*.field}"

     if (!changeItems.any { it.field in listOfFields }) {

        //don't run the listener if the user changed an unrelated field.

        log.warn "$listOfFields were not found in the list of changed fields."

        return null

    }

      if ( changeItems.any { it.field == ‘Fix Version’ }).

    {

        issue.setCustomFieldValue(customField, null)

          customField.updateValue(null, issue, new ModifiedValue(customFieldValue, null), new DefaultIssueChangeHolder())

    }

}

Tried both customField.updateValu and issue.setCustomfield methods, but getting the syntax errors.

Please help.....

Suggest an answer

Log in or Sign up to answer