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
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:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Senior Support Engineer
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lakshmi S
log.warn "=========>>>> ${new Date(System.currentTimeMillis())}"
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:-
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:-
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your detailed explanation @Ram Kumar Aravindakshan _Adaptavist_
Please find the attached screenshots for your reference as your above comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:-
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:-
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.