Hello,
I am using set field value (from groovy expression) post function.
My requirement is to update a select list field (with options shift 1 m, shift 2, shift 3 etc) based on the "hour" value which should be extracted from custom field date time picker type.
I use the groovy expression :
issue.getAsString(
"Begin Date"
)
which is giving complete timestamp including date as shown in screenshot below:
Can i extract only the time value?
I appended getTimeString() to the above code but it doesnt seem to work.
Any help?
Thanks!
Swathi
Hi,
you can use all the methods of the Date class on the result of issue.get("Begin Date"): https://docs.oracle.com/javase/7/docs/api/java/util/Date.html
For example, to get the hours:
issue.get("Begin Date").getHours()
Note that Java doesn't have a class to represent just a time value (without a date), so you'll have to manipulate the hours, minutes and seconds as numbers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using set field value postfunction
i have tried to copy, ( time-to-resolve) scripted field value in seconds,
to a text field( time-to-resolve(())
which gives output in seconds,
how do i get the value in (prettyduration format) ? ex( 2w 3d 1m)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shiva,
you can use this:
${com.atlassian.core.util.DateUtils.getDurationString(issue.get("Time-to-resolve"))}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you,
That work like a charm!!
can i get in jira format ( where it takes jira date format)
where 5 days a week and 8 hours a day ( like prettyduration)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, use this instead:
getComponent(com.atlassian.jira.util.JiraDurationUtils).getShortFormattedDuration(issue.get("Time-to-resolve"))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks David,
i have added this to post function, But i get the text copied to field as below,
Text is directly copied to the field "time-to-receive(())" text field
Did i miss any fixes ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I provided the Groovy code. In a Groovy template, just wrap it with ${ and } just like in the previous example:
${getComponent(com.atlassian.jira.util.JiraDurationUtils).getShortFormattedDuration(issue.get("Time-to-resolve"))}
just
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it Works!!
Thanks for the response.
last step. ( the scipted field shows the result as below)
but the copied text shows,
the script i use is as below, should i divide by 3600 , to get the data as ( 8hours perday,5days per week)
==============================================
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue;
import com.atlassian.core.util.DateUtils
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def inprogressname = "Resolve"
List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->
//def timeDiff = item.created.getTime() - issue.getCreated().getTime()
def timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()
if (item.fromString == inprogressname) {
rt << -timeDiff
}
if (item.toString == inprogressname){
rt << timeDiff
}
}
//return (Math.round(((rt.sum() as Long) / 3600) as Long))
def total = rt.sum() as Long
return (total / 1000) as long ?: 0L
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No. You are calculating the field value as a time difference between two date/time values. This is, by definition, an absolute duration in calendar time, meaning it includes nights and weekends. Therefore, you can't convert it/display it in working time, because it would require calculating the time, between the two date/times, spent during working hours only, which is far from trivial.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Got it , thanks .!! David
Thanks for the help.
Can you direct me where I can Browse >> (calculating time in all statuses of workflow)sum of all the statuses.
or any script you are aware of which gives time between statuses with nights & weekends excluded
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure I understood the first question. As for the second, it's not as easy as it looks, as you need to take time zones into account, and potentially holidays, vacations, etc.
Maybe someone can share their solution? I don't have a good one for that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the script i have is for adding time in status for single status,
How do i add time in two statuses, when i add 1st status open it shows blank,
if i add other statuses , other than the first it gives an output.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer ,
I tried using same as above syntax (one with the post-func) but it doesn't work on my config set-up...
scripted customfield to hours is:
TOTAL TIME TO: Ticket Age (hrs) =
while customfield destination to copy in prettyformat is:
PretDur Ticket Age
Applied your reco syntax:
${com.atlassian.core.util.DateUtils.getDurationString(issue.get("TOTAL TIME TO: Ticket Age (hrs) ="))}
result: it did not display at all the 'PretDur Ticket Age' field
i tried adding a set of { } in curr syntax as experiment;
it displayed the 'PretDur Ticket Age field but value is single closed bracket }
can you pls. help to isolate what I'm missing? thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Luz Silverio ,
The question and solution we're for Jira Server/DC. JMWE for Jira Cloud uses a different syntax. You should create a separate Community question, or check out the appropriate product documentation for the cloud.
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.
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.