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
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()
}
Hello,
It would be nice to see your script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
}
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.