Set field value from Javascript

Martin Burton December 9, 2013

Hi,

We need to be able to set the value of the Due Date based on the values of several others. In Jira 4.0.1 we do this using Javascript in the description of the Due Date. This sets the Due Date value using:

document.forms.jiraform.duedate.value = return_val;

However in Jira 5 this is not working. I have verified the return_val is being set - it is in the form dd/mmm/yy e.g. 10/Dec/13.
Please could someone suggest an alternative method.
Thanks,
Martin.

5 answers

1 accepted

0 votes
Answer accepted
Alex Perez
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 9, 2013

What about creating a listener to manage all events from you project?

If JS doesn't work for you, this may be a valid alternative.

The listener should check if the event is coming from a "controlled project" and check if the due date equals to calculated due date ...

some examples

https://developer.atlassian.com/display/JIRADEV/Writing+JIRA+Event+Listeners+with+the+atlassian-event+Library

Martin Burton January 2, 2014

Hi,

I have decided to use a Groovy script as a post-function and have this working for one transition where the dependent fields can be modified. However it is not working when I add it as a post-function to the Create transition. The script uses the following:

MutableIssue mutableIssue = (MutableIssue) issue;
def setDueDate = mutableIssue.getDueDate();
// Calculates newDueDateCal based on other field values

Timestamp dueDate = new Timestamp(newDueDateCal.getTimeInMillis());
mutableIssue.getPriorityObject();
log.debug "Setting Due Date to " + newDueDateCal.format("dd/MMM/yyyy");
mutableIssue.setDueDate(dueDate);

The script is running and calculates a newDueDateCal correctly, as shown by the debug output. However the issue that is created does not have the Due Date set.

Thanks,

Martin.

Alex Perez
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 3, 2014
Martin Burton January 5, 2014

Thanks, that works.

How do I accept this answer?

Alex Perez
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 5, 2014

Check the "tick" mark near to the response.

Glad to see that worked!

0 votes
Martin Burton January 5, 2014

Thanks, that works.

0 votes
Alex Perez
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 3, 2014
Ensure that your postfunction is the first in the postfnction list, on the create step ... https://confluence.atlassian.com/plugins/servlet/mobile#content/view/290750897
0 votes
RambanamP
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 9, 2013

share your javascript which used in jira 4.0, will help to make it work on jira 5.x

0 votes
Higashi
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 9, 2013

Maybe you could use jira behavoiurs plugin?

From the plugin description:

The behaviours plugin allows an administrator to create one more or behaviours, which can be thought of as "Behaviour Schemes". A behaviour defines how fields behave. Some examples of behaviours are:

Setting a field value dependent on other form data

Suggest an answer

Log in or Sign up to answer