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,938
Community Members
 
Community Events
176
Community Groups

Custom listener to update field when issue commented on

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

1 vote

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.

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events