Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Ramesh Penuballi December 13, 2022

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
PD Sheehan
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.
January 4, 2023

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.

0 votes
Ramesh Penuballi December 22, 2022

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
Vamsi Kandala
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.
December 22, 2022

Hi @Ramesh Penuballi

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

Thanks,
Vamsi

0 votes
Ramesh Penuballi December 20, 2022

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