Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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.  

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

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

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

JSM June Challenge #2: Share how your business teams became ITSM rockstars

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...

298 views 9 7
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