Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

22 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you