I added below groovy script to duedate of sau tasks to prevent subtasks accept Duedate value more that their parents, this is work in create issue, but in edit issue, my code does not work and the below error shown in log:
Cannot invoke method getDueDate() on null object
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()
}
It got OK, by help of my friend:
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
}
Hi,
Could you clarify where this script is being used? Your question title says "Scripted Field" but this looks like a script for a behaviour?
@BaseScript FieldBehaviours fieldBehaviours
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you limited this behaviour to just sub-tasks? If it's run on parent level issues, it's going to throw this error because the parent of a parent level issue is always going to be null.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I change the mapping and now it is mapped to all Project and all issue types and the problem still there is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, that's the opposite of what I said - this Behaviour either needs to
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes it check first the issue is sub task or not and it it is then continue. Any way i test the code for both status. Only sub tasks and all issue types. But it only work in create issue and not edit issue
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.