Automatic set Due Date the end of the month

Kristiyan Nachov February 2, 2021

Hello,

 

I want to set automatically due date to be the last day of the month. Is there a script for scriptrunner with which to do it?

 

Thank you in advance

1 answer

1 accepted

0 votes
Answer accepted
Tessa Tuteleers
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2021

Hi @Kristiyan Nachov , 

you can without a doubt script that (as a behaviour or postfunction, based on your needs), and you can find a lot of info about working with dates here.

However, if scripting does not come easy to you, you might want to try automation for jira (there is a free lite version for server) where you can add a trigger, and then edit the issue with 

duedate = {{now.lastBusinessDayOfMonth}} 
or 
duedate = {{now.endOfMonth}}


hope this helps, 

- Tessa

Kristiyan Nachov February 2, 2021

I apologize but I did not explain well. I want the default value of the field Due Date to be the last day of the month. This is the script we used in the previous version of the Jira.

<script type="text/javascript">
var monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];

var today=new Date();
var dd=today.getDate();
var mm=today.getMonth()+1; //January is 0!
var yyyy=today.getFullYear().toString();
var res = yyyy.substring(2, 4);
var dd = new Date(yyyy, mm, 0);
var d = dd.getDate();

today=d+'/'monthNames
[mm-1]
'/'+res;

dueDateField = AJS.$("#duedate");

if (!dueDateField.val())

{ dueDateField.val(today); }

;

</script>

This script was in description of Due Date field.

However, after we upgraded to version 8.14.1, this is what happened.Capture.JPG

Tessa Tuteleers
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2021

Hi @Kristiyan Nachov , 

You are very right, Javascript in field description is no longer supported from Jira 8+.
Might have mentioned these things right away for quicker resolution ;) 

As I mentioned before, you should use a behaviour with groovy script to do this from now on. 
Ping if you need a little help with the scripting, but Adaptavist has extensive info available to set you on the right track. 

Good luck! 

- Tessa

Kristiyan Nachov February 2, 2021

Thank you very much.

I am starting to explore adaptavist.

Daniel Ebers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2021

This suggests the script is not interpreted currently due to security reasons.
In case you want to get the functionality back you would need to switch HTML in custom field description back "on".

Please see the following guide:

https://confluence.atlassian.com/adminjiraserver087/configuring-jira-application-options-998872637.html

The option is named: Enable HTML in custom field descriptions and list item values

The background of this change is as follows:
https://jira.atlassian.com/browse/JRASERVER-70859

Kristiyan Nachov February 2, 2021

It looks great.

But when I enable this function and enter our script, this is the error:

Capture.JPG

 

Is the problem in our script?

Daniel Ebers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2021

Probably yes, it complains about Line: 16/Column: 12 - with some likeliness it is not compatible anymore.

Kristiyan Nachov February 3, 2021

<script type="text/javascript">
var monthNames = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
];

var today=new Date();
var dd=today.getDate();
var mm=today.getMonth()+1; //January is 0!
var yyyy=today.getFullYear().toString();
var res = yyyy.substring(2, 4);
var dd = new Date(yyyy, mm, 0);
var d = dd.getDate();

today=d+'/'+monthNames[mm-1]+'/'+res;

dueDateField = AJS.$("#duedate");

if (!dueDateField.val())
{ dueDateField.val(today); };

</script>

 

Thats the script. If somebody needs it.

Like Tessa Tuteleers likes this
Tessa Tuteleers
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2021

Thanks for the correction @Daniel Ebers , Tempo stopped supporting extra javascript on the log work screen, but in Jira it is still possible, my bad! 

- Tessa

Daniel Ebers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2021

@Tessa TuteleersNo worries - the moment I clicked "Reply" I even was not sure by 100% anymore - because I read "Jira v8.14" but it seems (?) to work for the OP, however I hope having that understood well :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events