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

Custom listener to update field when issue commented on

Drishti Maharaj March 9, 2022

Hi,

I am trying to create a custom listener in where the field "Create Date & Time" is updated when an issue is commented on. The field should update to the date the issue was created on.

The reason for the listener is older issues were this fields needs to be updated. 

The script is as follows but it does not seem to work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.Issue 
 
def customFieldManager = ComponentAccessor.customFieldManager
def issue = event.issue
def cfValues = customFieldManager.getCustomFieldObjects(issue).findByName("Created Date & Time")
 
cfValues['Created Date & Time'] = issue.created
 
log.warn(issue.created)

 

Log Error:

2022-03-09 12:35:32,088 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2022-03-09 12:35:32,088 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingPropertyException: No such property: Created Date & Time for class: com.atlassian.jira.issue.fields.ImmutableCustomField at Script2015.run(Script2015.groovy:10)

 

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Nic Brough -Adaptavist-
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.
March 9, 2022

There's two things to look at here.

First, the technical one - the second to last line is trying to set a variable to the date/time an issue was created, but it does nothing with that variable, and that variable can't accept the value you're trying to set because the variable is already set to be a custom field, not a date/time value.

What you probably want to do is set the value of the custom field to the date/time you are working with.

Second, the reporting question - why are you setting a custom field to a value that already exists on the issue, and why is that useful every time someone makes a comment on the issue?  You already have the issue.created date/time stamped on it, and if you are actually looking for the last update (such as comment), then issue.updated is what you're looking for.

Drishti Maharaj March 9, 2022

So the system field "created" is not visible when you try to add it to a screen in a project on JIRA and if the field is not visible on the screen then you cannot see that field on the Aha Integration side. 

Which is what is needed - to see the "created" date.

The work around was a new custom field called "Created Date & Time" which is a date/time field that shows this information (you can add this to a screen and thus be visible on the Aha Integration).

Going forward, this custom field is updated with a post function on the workflow when an issue is created - that works fine.

However, the issue is with older tickets that need to be updated with this info (created date & time) - it is far too many tickets to attempt manually so that's why if possible with a listener. 

But I seem not to be getting it right - essentially copying the "created" value to "created date & time" on an issue

Nic Brough -Adaptavist-
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.
March 9, 2022

Eh?  That's not true, the created date is on the issue view screen automatically.  I've got no problem seeing it in Aha.

Drishti Maharaj March 9, 2022

Not sure then what is with our instance but we cannot seem to find it. Thanks though. Will have a look further. 

TAGS
AUG Leaders

Atlassian Community Events