Hi all,
I would like to create a calculated date field with the misc custom field addon which does the following:
I have 1 Main Issue with a couple of subtasks. The calculated date fields are only relevant in the subtasks.
In the subtasks it is possible to set a dependency to another subtask, this is done via an issue link, link type: 'depends on' (e.g. subtask 1 can only be started after subtask 2 is finished). The calculated date should now calculate the date based on the due date of the linked subtasks + x days (the x days is the value which I have in another custom field).
Is that possible?
You can try with a formula derived from the following:
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.link.IssueLinkManager; import com.atlassian.jira.user.ApplicationUser; IssueLinkManager ilm = ComponentAccessor.getIssueLinkManager(); ApplicationUser curUser = ComponentAccessor.getJiraAuthenticationContext().getUser(); linkedIssues = ilm.getLinkCollection(issue, user, true).getOutwardIssues("Dependency"); if (linkedIssues.size()>0) { Issue dependsOn = linkedIssues.iterator().next(); if (dependsOn.getDueDate()==null) return null; Long delta = issue.get("my field"); //assuming this is a Number field. Otherwise, needs to be converted to a Long Calendar dueDate = Calendar.getInstance(); dueDate.setTime(dependsOn.getDueDate()); if (delta) dueDate.add(Calendar.DAY_OF_YEAR, delta); return dueDate.getTime(); } else return null;
You'll need to adapt it to your needs:
For debugging, don't forget to watch atlassian-jira.log for errors. Also, you can use log.error("some text"); to write data to the logs for debugging purposes.
Thank you for the detailed answer! I will try that asap and will update you here if that worked for me.
Best regards
Dieter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found the time to test the script but even after some adjustments I could not get it to work. Im trying a different script now in a scripted field from the scriptrunner plugin. Nevertheless thank you for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dieter,
this is technically possible but the required script is a little complex. However, you should know something: the value of a calculated field is not stored in the database, but it is still stored in the JIRA index, which is used for searching as well as for the "List view". The index for an issue is updated only when that issue is transitioned or edited. As a consequence, if you modify a linked subtask's due date, this will not update the primary subtask, so search won't work as expected.
However, when you display the main subtask, its calculated fields will be re-computed (although the results won't be stored in the index) so the calculated field will be accurate then.
So, before anyone tries to help you write the formula, you need to decide whether this limitation is acceptable for your use case.
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
thanks for the quick Response and the explanation. This limitation is acceptable for my use case.
Best regards
Dieter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.