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

How To Set Date/Time Field into future based off another Date/Time Field & auto-fill out field

I'm looking to add a scriptrunner behavior on my Service Desk portal create form. I want to set the Date/Time field "Live End Time" to be defaulted to 60 minutes after "Live Start Time".  The Requester should still have the option to edit the field if they need to. 

I'm just starting out with scripting and most of the answers that I've seen on this board has talked about setting a field days into the future, but none, where it would auto-populate on after the first field, is set.  

Example:

Live Start Time = 5/May/21 05:00 PM 

When the user clicks out of this field, I want to auto fill out the Live End Time to read:

5/May/21 06:00 PM 

When the form loads, both fields are empty.  The user will fill out the Live Start Time field first.  After they fill it out, I want the Live End Time field to auto-populate.  

 

I have scriptRunner installed and I'm on Jira Server 8.15

 

Thank you 

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 05, 2021

Hi @Robert Kendrick I don't have any existing code snippet for JSM, but did you check this documentation https://scriptrunner.adaptavist.com/6.20.0/jira/behaviours-servicedesk.html? 

You will have to play with value in Live Start Time field (parse it correctly), add 1hour and set it as String to Live End Time.

I think that's what my issue is, as i'm having an issue parsing it correctly.  

I found this code example online that allows me to change the hour by 1, but I can't seem to get it to work at all if I'm bring in my "Live Start Time" field.  I've tied to bring it in as a LocalDateTime and as a Date but it never seems to pass thought.  

 

This code works but it's using "now" as the date instead of my custom field.  Any help on how I can bring in my custom field into this code?

 

//The time field my user is filling out 
def startTime = getFieldByName("Live Start Time")

//This is the field that the new time plus 1 hour will go into
def endTime = getFeidlByName("Live End Time")


SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MMM/yy hh:mm a");
Date date = new Date()



Calendar c = Calendar.getInstance();
c.setTime(date);

c.add(Calendar.YEAR, 0);
c.add(Calendar.MONTH, 0);
c.add(Calendar.DATE, 0);
c.add(Calendar.HOUR, 1);
c.add(Calendar.MINUTE, 0);
c.add(Calendar.SECOND, 0);

// Convert calendar back to Date
Date currentDatePlusOne = c.getTime();

endTime.setFormValue(dateFormat.format(currentDatePlusOne))
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 12, 2021

I just found out the script which describes how to work with Jira properties (Date/DateTime formats) and translate Object to String using the properties. You need to do it in the other way around. If you're Java developer, you will be able to do it, otherwise try to prepare at least some snippet of the code so we can work on it together :)

https://library.adaptavist.com/entity/set-the-value-of-date-or-date-time-fields

Sadly, I am not a Java developer, but I am trying to learn as much as I can.  

I'll spend some time working inputting my custom fields into this code and see if I can get anything to work.  

When I have additional questions I'll come back.  

Thank you for your help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events