Hi,
I am trying to implement a scripted field which will calculate time between issue created and first comment added to it. can someone please help with the script. I am not sure how to capture comment time in script.
Hi all,
There are multiple solutions for sure. Just another solution might be Enhancer Plugin's Response Time Calculators which covers everything without a line of code.
I'm one of the folks behind Enhancer Plugin, pleae let me know if you need further assistance.
Cheers
Tuncay
I'm not sure about ScriptRunner, but using JMCF, you would write something like this:
if (!issue.get("comment"))
return null;
return new Date().time - issue.get("comment").first().created.time
which would return a number of milliseconds.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you David!
I have used the following code :
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
DateUtils.getDurationString(
((comments[0].created.getTime() - issue.getCreated().getTime()) /1000)as Long)
It is giving me the desired result. please suggest if your one is more optimized? i can use that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No. Mine would only work with JMCF or JMWE, not ScriptRunner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That script looks fine for scriptrunner. The only thing is you will get an error if there are no comments.
You could use the following if you wanted to display the time elapsed so far:
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
def comments = ComponentAccessor.commentManager.getComments(issue)
def endTime = new Date().time
if(comments){
endTime = comments.first().created.time
}
DateUtils.getDurationString(
((endTime - issue.created.time )/1000) as Long
)
Or make a small adjustment to return null when there are no comments.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This part...
(endTime - issue.created.time )/1000
Returns the number of seconds.
So if you want minutes, just divide by 60.
Maybe something like
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
def comments = ComponentAccessor.commentManager.getComments(issue)
def endTime = new Date().time
if(comments){
endTime = comments.first().created.time
}
Math.floor((endTime-issue.created.time)/1000/60)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
Thank you for your immediate response.
I am getting "Can not find matching method error" but it showing the exact result.
And i need to show the result of Assignee first comment time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is only a warning that can be ignored. The script editor attempts to warn you that you MIGHT have some type of error. It tries to guess what methods are valid and help you correct mistakes. But it can't know everything and groovy can have dynamic typing.
If you really insist to make the error go away, you can coerce the type
Math.floor((endTime-issue.created.time)/1000/60 as Integer)
To get the first comment from the assignee you can try this:
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
def comments = ComponentAccessor.commentManager.getComments(issue)
def endTime = new Date().time
if(comments){
def authorComment = comments.findAll{it.authorApplicationUser == issue.assignee }
if(authorComment){
endTime = authorComment.first().created.time
return Math.floor((endTime-issue.created.time)/1000/60 as Integer)
}
}
return null //in case there are no comment or no comments by the assignee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.