• Community
  • Products
  • Jira
  • Jira Core
  • Questions
  • Hi, is it possible to set "Due Date" field value on "Create" transition using "Set Field Value to constant or Groovy expression Function" post function?

Hi, is it possible to set "Due Date" field value on "Create" transition using "Set Field Value to constant or Groovy expression Function" post function?

I am trying to set a value of "Due Date" field to some value (current date or current date + 5 days) using JMWE post function, but no results. Can anyone advise something on this matter? 

6 answers

1 accepted

This widget could not be displayed.

It is indeed possible, but you need to look at the Java documentation for the Date class (your snippet above is incorrect). 

And you should see an error message in Atlassian-Jira.log right after displaying an issue that should show your calculated field. 

Finally, you can use Java Date methods to get the current date as well as to add to a date. 

Thanks, was able to implement.

Good!

Care to share your solution here?

This works in my case: due date (=current date) + 9 days.

import java.text.SimpleDateFormat;
import java.util.Date;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yy");
Date dt = new Date();
long time = dt.getTime()+9*24*60*60*1000;
String duedate = sdf.format(time);

duedate.jpg

pf.jpg

@abstractelement, Could you please help to modify above script to work only for due date. That is Due Date should be set as on when transition is made. I tried modifying the below line in above script but it didn't work.

long time = dt.getTime();

 Thanks,

Do you use JMWE plugin or some another plugin? What is the date pattern for your JIRA instance? What have you configured in details?

Hi Suresh, I'm not sure I understood what you're trying to do. Are you trying to set the Due Date field to "now"? If so, just use the following script:

new Date()

Hi David,

Thank you for your quick response.

Yes, your understanding is correct. I want to set Due Date to "now".  Could you please provide the complete script David. 

Yes, we do have a JMWE plugin where I have configured start date. However, Due Date isn't mentioned in the drop down list. So, need help with the script to implement the same. Due Date should choose the system date on when this transition is done.

Date format: dd/MMM/yy

Thanks in advance.

Hi David,

Thank you for your quick response.

Yes, your understanding is correct. I want to set Due Date to "now".  Could you please provide the complete script David.

Yes, we do have a JMWE plugin where I have configured start date. However, Due Date isn't mentioned in the drop down list. So, need help with the script to implement the same. Due Date should choose the system date on when this transition is done.

Date format: dd/MMM/yy

Thanks in advance.

Hi David,

Thank you for your quick response.

Yes, your understanding is correct. I want to set Due Date to "now". Could you please provide the complete script David.

Yes, we do have a JMWE plugin where I have configured start date. However, Due Date isn't mentioned in the drop down list. So, need help with the script to implement the same. Due Date should choose the system date on when this transition is done.

Date format: dd/MMM/yy

Thanks in advance.

Hi David,

Thank you for your quick response.

Yes, your understanding is correct. I want to set Due Date to "now". Could you please provide the complete script David.

Yes, we do have a JMWE plugin where I have configured start date. However, Due Date isn't mentioned in the drop down list. So, need help with the script to implement the same. Due Date should choose the system date on when this transition is done.

Date format: dd/MMM/yy

I don't understand by what you mean by "we do have a JMWE plugin where I have configured start date".

Anyway, in the "Set Field Value (JMWE add-on)" post-function, the Due Date field should appear in the list of fields. And all you need is to set the value to the following Groovy expression:

new Date()

Which version of JMWE and Jira are you using?

David, Sorry there was a mix up here.. My answers were for you and @abstractelement.

We can implement Start date field to pick transition date through JMWE plugin in Jira, however for Due Date it's not possible. Hence, other way is to do this using script-post function offered by Adaptavist Script runner. 

David: I am clear with your answer now, I'll check and confirm the same.

Fyi.. Jira - 7.6.3 and JMWE: 5.1.1

I don't understand why it's not possible for Due Date...

Also, you can also create a Scripted (Groovy) post-function using JMWE...

Thanks David for quick response. There is no Due Date in the drop down list, when tried to implement the same way as when using Start Date(used "Update Issue Custom Field (JSU)". This is offered by Suite Utilities for Jira (JSU). Sorry for creating confusion. 

Thanks a lot. I'll test the way you have advised.

This widget could not be displayed.

Might be worth explaining

  • exactly what you have configured 
  • what the error is (if you get one on screen)
  • what the log file says when you create a new issue with the post-function
This widget could not be displayed.
  1. I just want to know if such functionality is available in JMWE plugin. I was able to set value for "Original Estimate" field in the following way:Screenshot_1.jpg
    However, no luck with "Due date" field if I use for example: new Date(2016-05-01)

    Also, wondering if possible to get current date and set it for due date with some additional value.
     
  2. No errors
  3. Nothing, just record with error without any hint.

This widget could not be displayed.

It should be, but you'll need to tell us more about what you're trying.

We probably still need to see the error message.

This widget could not be displayed.

Thank you for your replies.

This widget could not be displayed.

Actually, something like: 

import org.apache.commons.lang3.time.DateUtils;
return DateUtils.addDays(new Date(), 9);

would be simpler.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published 6 hours ago in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

38 views 0 8
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you