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
Community Members
Community Events
Community Groups

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.  


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

Hi @Robert Kendrick I don't have any existing code snippet for JSM, but did you check this documentation 

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.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();


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 :)

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
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

179 views 1 6
Read article

Atlassian Community Events