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
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();
// 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 :)
For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...
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