Limit Duedate of Subtasks based on their Parents

Crs co November 25, 2017

Hi,

I want to write an script that limit the sub tasks due date based on the value of their parents, I write an script as behavior and tag it to due date field and it works well in create issue but not in edit issue. I cant find why and what the problem is, I will appreciate to help me to resolve it

3 answers

1 accepted

0 votes
Answer accepted
Crs co December 29, 2018

Hi,

I updated my JIRA to 7.1.4 and now I have problem with my old code, now the code does not work.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import java.lang.Object


import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.web.util.OutlookDate
import com.atlassian.jira.web.util.OutlookDateManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript


import com.atlassian.jira.issue.CustomFieldManager
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.web.action.util.CalendarResourceIncluder
import static com.atlassian.jira.issue.IssueFieldConstants.*

import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

@BaseScript FieldBehaviours fieldBehaviours
FormField DueDate = getFieldById(getFieldChanged())
//def DueDate = getFieldById(getFieldChanged())
//FormField field = getFieldById(getFieldChanged())
FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long

if (!parentIssueId || DueDate.getFormValue()) {
// this is not a subtask, or the field already has data
return
}

def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()


def DueSubtask = DueDate.getValue()

Date newDueSubtask = (Date)DueSubtask
Date DueTask = parentIssue.getDueDate()

if(newDueSubtask.compareTo(DueTask)>0) {
DueDate.setHelpText("Duedate can not be after Task Duedate, Insert the a properiate Date")
DueDate.setFormValue("")

} else {
DueDate.clearHelpText()

}
1 vote
Alexey Matveev
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.
November 25, 2017

Hello,

It would be nice to see your script.

Crs co November 25, 2017

sorry I forgot it.

My code is :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import java.lang.Object


import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.web.util.OutlookDate
import com.atlassian.jira.web.util.OutlookDateManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript


import com.atlassian.jira.issue.CustomFieldManager
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.web.action.util.CalendarResourceIncluder
import static com.atlassian.jira.issue.IssueFieldConstants.*

import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

@BaseScript FieldBehaviours fieldBehaviours
FormField DueDate = getFieldById(getFieldChanged())
//def DueDate = getFieldById(getFieldChanged())
//FormField field = getFieldById(getFieldChanged())
FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long

if (!parentIssueId || DueDate.getFormValue()) {
// this is not a subtask, or the field already has data
return
}

def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()


def DueSubtask = DueDate.getValue()

Date newDueSubtask = (Date)DueSubtask
Date DueTask = parentIssue.getDueDate()

if(newDueSubtask.compareTo(DueTask)>0) {
DueDate.setHelpText("Duedate can not be after Task Duedate, Insert the a properiate Date")
DueDate.setFormValue("")

} else {
DueDate.clearHelpText()

}
Alexey Matveev
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.
November 25, 2017

The problem is that in the Edit screen field "parentIssueId" does not exist. That is why if it does not exist then you should take the value from the issue. Replace

FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long

with

FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long
if (!parentIssueId) {
    parentIssueId =underlyingIssue?.getParentId() as Long
}
Crs co November 25, 2017

Wow, You are write and really thank you so much, I replaced it and it is OK

0 votes
Crs co November 25, 2017

My code is :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import java.lang.Object


import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.web.util.OutlookDate
import com.atlassian.jira.web.util.OutlookDateManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript


import com.atlassian.jira.issue.CustomFieldManager
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.web.action.util.CalendarResourceIncluder
import static com.atlassian.jira.issue.IssueFieldConstants.*

import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

@BaseScript FieldBehaviours fieldBehaviours
FormField DueDate = getFieldById(getFieldChanged())
//def DueDate = getFieldById(getFieldChanged())
//FormField field = getFieldById(getFieldChanged())
FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long

if (!parentIssueId || DueDate.getFormValue()) {
// this is not a subtask, or the field already has data
return
}

def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()


def DueSubtask = DueDate.getValue()

Date newDueSubtask = (Date)DueSubtask
Date DueTask = parentIssue.getDueDate()

if(newDueSubtask.compareTo(DueTask)>0) {
DueDate.setHelpText("Duedate can not be after Task Duedate, Insert the a properiate Date")
DueDate.setFormValue("")

} else {
DueDate.clearHelpText()

}

 

Suggest an answer

Log in or Sign up to answer