Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Auto inserting a duedate using the behaviours plugin

Warren McInnes
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.
January 7, 2013

Hi,

Is there a way to add a duedate automatically to a issue? Must it depend on certain data, or can we just add 1 day to 1 day projects or 3 days to 3 day projects? Was thinking of using the "Behaviours Plugin" but not sure exactly how?

Two senarios:

1. issues being created via email, obviously no due date is added, can for instance if it's sent to a project that requires 3 days to work on it, add current date + 3days?

2. we would like this to be done in a workflow, so we can setup many workflows with different duedate requirements that could get populated automatically.

From my research something can hopefully be done through a script of some sort of perhaps a plugin. If there's a free way to do this, please help?

Thanks in Advance

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
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.
January 7, 2013

The benefit of using the behaviours plugin is that you can default the due date to 3 dates hence or whatever. Optionally you can make it readonly as well.

But the behaviours plugin does not operate on issues created by email, or by the API in general.

If you just want to set it, and not default it, I'd use a script that runs as a post-function of the creation action, eg:

issue.dueDate = new Date() + 3 // do your date logic here.

I'd also remove the due date from the create screen, otherwise you will frustrate your users when you overwrite it.

Warren McInnes
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.
January 7, 2013

Hi Jamie, Thanks for your prompt response

How do i do this:

The benefit of using the behaviours plugin is that you can default the due date to 3 dates hence or whatever. Optionally you can make it readonly as well.

as i am unfimilar with the behaviours plugin?

Why would it not work on issues that come in via email, surely they have to conform to the assigned workflow process?

Does the automated duedate process you mention above using the behaviours plugin work within the workflow and do you add it as a post-function?

Forgive my ignorance


JamieA
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.
January 7, 2013

You'd have to read the docs... the reason it doesn't work with emailed issues is that it's purely javascript based, which is why I suggest to use a post-function script (script runner plugin) to do it.

It's possible to use both if it's really necessary.

> Does the automated duedate process you mention above using the behaviours plugin work within the workflow and do you add it as a post-function?

No, you map behaviours to projects, they are orthogonal to workflows. My groovy script suggestion (which I believe is correct for you) is part of the workflow. If you prefer, substitute "your home-grown java plugin" for groovy script.

I think there are other plugins that can set a date using some simple arithmetical rules.

Warren McInnes
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.
January 7, 2013

If I would perfer to do the process in a workflow, then would I then just be using groovy in the post-function with a script runner instead of using the behaviours plugin.

Or

If I use the Behaviours plugin, it would be per project that I set the duedate and restrict user input for this field, but this won't work for incoming emails?

am I correct in saying this?

Secondly,

With your code:

issue.dueDate = new Date() + 3

Could I not add something like:

If issue.dueDate = null

then issue.dueDate = new Date() + 3

else get.dueDate.value from input data as per regular workflow or whatever the code is using groovy?

JamieA
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.
January 7, 2013

> am I correct in saying this?

Mostly. You can apply the same behaviour to multiple projects then use some server-side code to control what the actual value of the due date should be. You could base that on project or any other information.

> Could I not add something like

Absolutely, use any logic you like...

JamieA
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.
January 7, 2013

Not sure what you're looking for exactly...

Warren McInnes
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.
January 7, 2013

Sorry Jamie, Where exactly can I find such Documentation on

The benefit of using the behaviours plugin is that you can default the due date to 3 dates hence or whatever.

I've read through some of documentation found here, but no luck?

https://studio.plugins.atlassian.com/wiki/display/JBHV/JIRA+Behaviours+Plugin

Thanks

Warren McInnes
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.
January 7, 2013

Alright, where would I go to get more information on the behaviours plugin and adding the duedate through using the behaviours plugin?

JamieA
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.
January 7, 2013

I'd read the docs and some of the other questions here, go through the examples. Having done that you'd see how to set the due date in the form. I don't think you want the behaviours plugin though, for the email reason.

Tuan Vo December 2, 2014

Jamie, I used the line of code you provided: issue.dueDate = new Date(), in the post function area; however, it is not working for me.

JamieA
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.
December 2, 2014

Not sure what you mean by the post-function area... this should be a "groovy custom post-function", with that code. Can you attach a screenshot>

Tuan Vo December 19, 2014

Hi Jamie, I am now trying to accomplish this task via the behavior plug-in. In the server side script area, I added these line of code: def today = new Date() def targetDate = today + 90 FormField dueDate = getFieldByName("Due Date") dueDate.setFormValue(targetDate) However, the dueDate field is not updated as expected. I appreciated any help or direction you can provide. Tuan

JamieA
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.
December 22, 2014

This is how you can set the due date: getFieldById("duedate").setFormValue((new Date() + 7).format("dd/MMM/yy")) You should look up the date format that the user will use though. You need to also check the field is empty before updating it.

Tuan Vo December 24, 2014

Hi Jamie, Thank you for getting back to me. Based on your suggestion, I rewrote the codes as follow in the behavior serverside script window: FormField dueDate = getFieldById("duedate") if (dueDate.getValue() == null) { dueDate.setFormValue((new Date() + 7).format("dd/MMM/yy")) } However, the dueDate field is not updating the value as expected. Do you see anything wrong with my code? Tuan btw, happy holiday; I appreciate your help.

Tuan Vo December 24, 2014

the date format in my Jira instance is "dd/MMM/yy"

JamieA
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.
December 29, 2014

your code is pretty much the same code. Try without the if() statement. If that doesn't work change the log level to debug from the "admin -> behaviours" page, then retry the action, and post what is logged in atlassian-jira.log.

0 votes
Renjith Pillai
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.
January 9, 2013
Warren McInnes
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.
January 9, 2013

Hi Renjith,

It is but it isn't, I don't want it to work as per issue or by priority type, but perhaps by project.

But it could work on a similiar concept. Would be nice if Mizan could comment on this?

Renjith Pillai
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.
January 9, 2013

That is a minor change Warren. Just changed Mizan's code. I have not tested it.

import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
   
// initializing the projects
  
  
def PA = 1;
def PB = 2;
def PC = 3;
def PD = 9;
def PE = 30;
   
  
// calender which returns the date according to the project defined
  
private GregorianCalendar getDate(double roll){
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        cal.set(Calendar.MILLISECOND,0);
   
        for (int x=0;x<roll;x++){
                cal.add(Calendar.DAY_OF_MONTH,1);
        }
   
        return cal;
}
   
   
  
MutableIssue mutableIssue = (MutableIssue) issue;
def project = issue.projectOject.name;
def setDueDate = mutableIssue.getDueDate();
 //only set the dueDate if the date isn't already set (i.e. if it == null).
  
        GregorianCalendar cal;
  
         if(project.equals("PA")){
                cal = getDate(PA);
        } else if(project.equals("PB")){
                cal = getDate(PB);
        } else if(project.equals("PC")){
                cal = getDate(PC);
        }
        Timestamp dueDate = new Timestamp(cal.getTimeInMillis());
        mutableIssue.setDueDate(dueDate);

Warren McInnes
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.
January 10, 2013

With this code would i require any additional plugins for it to work?

Got this error:

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: projectOject for class: com.atlassian.jira.issue.IssueImpl Possible solutions: projectObject

Renjith Pillai
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.
January 10, 2013

change projectObject to getProjectObject()

Warren McInnes
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.
January 10, 2013

I now get this issue?

javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getTimeInMillis() on null object

Renjith Pillai
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.
January 10, 2013

That is for @Mizan to comment ;)

JamieA
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.
January 10, 2013

That script is not written very well. It means that getDate was called. It looks like it is matching on project key, in which case it should be issue.projectObject.key. Also it should have an else {} block otherwise you will get this NPE.

Warren McInnes
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.
January 10, 2013

I'm trying something different.

I managed to get the "Created" Date copied into the "Due" Date field, now i want to try right a post-function to add X day/s to the due date field.

I tried to use something like this

def newDueDate = (getCreatedDate + 3)

issue.dueDate?.before(newDueDate)

but got this error?

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: getCreatedDate for class: Script8

Renjith Pillai
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.
January 11, 2013

Use issue.getCreated() or issue.created

Warren McInnes
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.
January 13, 2013

Ok This Validates true:

def newDueDate = (issue.getCreated() + 3)

issue.dueDate?.before(newDueDate)

But this will only check whether the condition is true, How do i get it to perform the action?

Any suggestions?

Renjith Pillai
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.
January 13, 2013

That was there in the earlier code I guess,

MutableIssue mutableIssue = (MutableIssue) issue;

mutableIssue.setDueDate(dueDate);

Renjith Pillai
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.
January 13, 2013

Ah, it is much more complicated that that. You need to put that into a script - read the big blue banner at https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner#ScriptRunner-Conditions%2CValidators%2CPostFunctions

Warren McInnes
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.
January 13, 2013

I'm just checking to see if i understand,

This:

MutableIssue mutableIssue = (MutableIssue) issue;

mutableIssue.setDueDate(dueDate);

Helps this action to perform?:

def newDueDate = (issue.getCreated() + 3)

issue.dueDate?.before(newDueDate)


In the workflow through a post-function, but which post-fuction should i select?

Add Parameters To Function

Add required parameters to the Function.
Built-in Scripts

Adds a comment to all blocked issues when this issue is transitioned.
Useful for alerting participants of other issues that a blocker is resolved, etc.
This function should be put on the Resolve transition (or similar).

Send a custom email
Send an email based on the provided template if conditions are met

Fast-track transition an issue
If the condition is met, automatically transition this issue to another status

Clones an issue and links.
Clones this issue to another issue, optioninally in another project, and optionally a different issue type.

Transition parent when all subtasks are resolved
This will do the given action on the parent when all sub-tasks are resolved

Create a sub-task.
Create a sub-task. Will optionally reopen a matching sub-task.

Fires an event when condition is true
Fires an event that can be picked up by a notification scheme, in order to send mail only under certain conditions, eg Priority is Blocker

Adds the current user as a watcher
Adds the user performing the action as a watcher, if condition applies

or
Script file path: <input style="margin: 0px; padding-top: 0px; padding-bottom: 0px;" type="text" name="filename" value="" size="100" maxlength="255"/>
Warren McInnes
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.
January 13, 2013

Alright Thanks

0 votes
Renjith Pillai
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.
January 7, 2013

Or how about a Listener using Jamie's plugin to automatically set a due date whenever and issue is created? Jamie, comments?

JamieA
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.
January 7, 2013

Yes, that would work fine too. A listener is the same as a post-function (in essence) except separated from the workflow.

TAGS
AUG Leaders

Atlassian Community Events