Copy the Assignee of the ticket comment on the ticket to custom date field

Lakshmi S
Contributor
March 19, 2024

Hi Team,

We have a custom field "Last Commented By Assignee" date field.

How to copy the latest date and time stamp when the current ticket assignee commented on the ticket?

"Last Commented By Assignee" date field should take the date value of the current assignee of the ticket comment on the ticket

2 answers

1 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _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.
March 21, 2024

Hi @Lakshmi S

For your requirement, I suggest using the ScriptRunner Listener and setting the Event to Issue Commented Event.

Below is a sample working code for your reference:-

import java.text.SimpleDateFormat

def issue = event.issue

def simpleDateFormat = new SimpleDateFormat('dd/MMM/yy h:mm a')

if (issue.comments.last().authorApplicationUser == issue.assignee) {
issue.update {
setCustomFieldValue('Latest Comment', simpleDateFormat.format(issue.comments.last().updated))
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

In the sample code above, I have used ScriptRunner's HAPI feature for simplification. To pass the Date and Time value from the latest comment to the Date Time field, you must ensure that the Date Time format is set correctly. To achieve this, I have used the SimpleDateFormatter, i.e.:-

def simpleDateFormat = new SimpleDateFormat('dd/MMM/yy h:mm a')

You will then need to use the format option to convert the Date value into String and set it according to the format above for it to be acceptable by Date Time field.

Below is a screenshot of the Listener configuration:-

listener_config.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

Senior Support Engineer

Lakshmi S
Contributor
March 21, 2024

Thank you @Ram Kumar Aravindakshan _Adaptavist_ ,

The script is perfectly working, but the comment time and the field time is not matching. Am I doing anything wrong ?

I commented on the ticket 03/21/2024 12:41PM , but the field "Assignee Last Comment Date" is showing 21/Mar/24 5:41 PM.

date_field.png

Ram Kumar Aravindakshan _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.
March 21, 2024

Hi @Lakshmi S 

There is nothing wrong with the code.

From your last comment, I suspect the time set in your Jira environment is set according to your Database or Server time.

To confirm this, you can do a simple test, i.e. go to the ScriptRunner Console, run the code below and see what output is returned.
log.warn "=========>>>> ${new Date(System.currentTimeMillis())}"

 

Thank you and Kind regards,

Ram

 

Lakshmi S
Contributor
March 22, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

This is output of the above code in scriptrunner console.

2024-03-22T15:41:52,124 WARN [runner.ScriptBindingsManager]: =========>>>> Fri Mar 22 15:41:52 UTC 2024

 

This is my system date and time


System Date Friday, 22 Mar 2024
System Time 15:41:52 +0000

 

How should we match the both timings as mentioned here?

I commented on the ticket 03/21/2024 12:41PM , but the field "Assignee Last Comment Date" is showing 21/Mar/24 5:41 PM.

look.png

Ram Kumar Aravindakshan _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.
March 25, 2024

Hi @Lakshmi S

In the log output you provided, it's clear your server is set to UTC time, as shown in the quote below:-

This is output of the above code in scriptrunner console.

2024-03-22T15:41:52,124 WARN [runner.ScriptBindingsManager]: =========>>>> Fri Mar 22 15:41:52 UTC 2024

 

This is my system date and time


System Date Friday, 22 Mar 2024
System Time 15:41:52 +0000

Please clarify are you currently located in a UTC time zone? If not, then you will need to update your server time to match your current time zone.

Alternatively, if you are located in a UTC time zone, you will need to update your laptop or desktop computer to match your Server Time.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Lakshmi S
Contributor
March 25, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ , 

No,Our system's time zone is CST, and I am located in MST. My laptop is also set to MST. All dates and times are correct except for this one.

Ram Kumar Aravindakshan _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.
March 25, 2024

Hi Lakshmi,

In your last comment, you mentioned:-

No,Our system's time zone is CST, and I am located in MST

If it is set to CST it should be UTC-6, but your log is showing UTC:-

2024-03-22T15:41:52,124 WARN [runner.ScriptBindingsManager]: =========>>>> Fri Mar 22 15:41:52 UTC 2024

System Date Friday, 22 Mar 2024
System Time 15:41:52 +0000

Your system time should be -0600 meaning 6 hours behind UTC. Instead, it is showing +0000 which means it is set to UTC time.

In my environment, the time is set to UTC+8, and my log output is something like this:-

2024-03-25 21:30:54,288+0800

Anyways, could you please try to set your Laptop Date to CST and try to rerun the test to see if there is a difference in the time set.

Thank you and Kind regards,
Ram

Lakshmi S
Contributor
March 25, 2024

Sorry Ram @Ram Kumar Aravindakshan _Adaptavist_ .

I changed my laptop time to CST as you suggested.

Before it was 

I commented on the ticket 03/21/2024 12:41PM , but the field "Assignee Last Comment Date" is showing 21/Mar/24 5:41 PM.

 

Now

commented on the ticket 03/21/2024 12:41PM , but the field "Assignee Last Comment Date" is showing 21/Mar/24 4:41 PM.

In the "General Configuration", its showing below.

timezone.png

Ram Kumar Aravindakshan _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.
March 25, 2024

Hi @Lakshmi S

In your last comment, you mentioned:-

Before it was 

I commented on the ticket 03/21/2024 12:41PM , but the field "Assignee Last Comment Date" is showing 21/Mar/24 5:41 PM.

 

Now

commented on the ticket 03/21/2024 12:41PM , but the field "Assignee Last Comment Date" is showing 21/Mar/24 4:41 PM.

This is most likely due to the time set on your server.

Please provide a screenshot of the time configuration on your Jira instance as shown in the screenshot below:-

timezone_config.png

This is to confirm what timezone in set on your Jira instance.

Also, go to Jira Administration > System > System Info  and show the timezone's configured as shown in the screenshots below:-

timezone2.png

 

timezone3.png

To override this configuration, please follow the steps provided in this Atlassian KB documentation.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

 

Lakshmi S
Contributor
March 26, 2024

Thank you for your detailed explanation @Ram Kumar Aravindakshan _Adaptavist_ 

Please find the attached screenshots for your reference as your above comment.

jiratime1.pngjiratime2.pngjiratime3.png

Ram Kumar Aravindakshan _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.
March 28, 2024

Hi @Lakshmi S

If you view the screenshot that was shared in your last comment, there are 2 different time zones set.

In the Default User timezone is set to GMT-6 i.e. UTC-6 as shown in the screenshot you shared:-

jiratime1_updated.png

Whereas the User Time Zone and jvm.system.timezone are set to UTC / GMT and not UTC-6 / GMT-6 as shown in the screenshots below:-

 

jiratime2_updated.pngjiratime3_updated.png

This clearly indicates that the clock configuration in your Jira environment is out of sync which is causing the result you are getting.

To resolve this, you must update the User Time Zone and java.system.timezone to UTC-6.

Please refer to this Atlassian KB document for more information on how to update the time.

Thank you and Kind regards,

Ram

Lakshmi S
Contributor
March 28, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

 Yes. Sure. Thank you for explaining the situation with the issue. You are a one of the valuable community member and have been helpful with our Atlassian-related inquiries.

Ram Kumar Aravindakshan _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.
March 29, 2024

Hi @Lakshmi S

Thank you for getting back.

I hope this answers your question.

Please accept the answer provided.

Thank you and Kind regards,

Ram

0 votes
Benjamin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 19, 2024

Hi @Lakshmi S ,

 

An Atlassian ticket has been created for this. There is some possible solutions provided in the ticket. Should be able to get it done switch SCriptRunner as I can see you have added that tag.

 

https://jira.atlassian.com/browse/JRASERVER-2734

 

Hope this helps

Suggest an answer

Log in or Sign up to answer