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,556,538
Community Members
 
Community Events
184
Community Groups

Set field value : Is there way to get only the time value from date time picker custom field?

Deleted user Nov 18, 2017

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: 

timevalue.pngCan i extract only the time value? 

I appended getTimeString() to the above code but it doesnt seem to work.

 

Any help?

 

Thanks!

Swathi

1 answer

1 accepted

0 votes
Answer accepted
David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 18, 2017

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.

Deleted user Nov 18, 2017

Thanks @David Fischer _Appfire_ !

It worked.

 

Regards

Swathi

@David Fischer _Appfire_ 

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)

 image.png

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 20, 2020

Hi Shiva,

you can use this:

${com.atlassian.core.util.DateUtils.getDurationString(issue.get("Time-to-resolve"))}

@David Fischer _Appfire_ 

 

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)

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 21, 2020

Yes, use this instead:

getComponent(com.atlassian.jira.util.JiraDurationUtils).getShortFormattedDuration(issue.get("Time-to-resolve"))

Thanks David,

i have added this to post function, But i get the text copied to field as below,

image.png

 

Text is directly copied to the field "time-to-receive(())" text field

     Did i miss any fixes ?

 

image.png

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 21, 2020

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  

Like shiva likes this

it Works!!

 

Thanks for the response.

 

last step. ( the scipted field shows the result as below)

image.png

but the copied text shows,

image.png

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

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 21, 2020

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.

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

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 21, 2020

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.

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.

Hi @David Fischer _Appfire_ ,

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 }

Screen Shot 2021-12-06 at 2.32.17 AM.png

can you pls. help to isolate what I'm missing? thanks.

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 05, 2021

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. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events