ScriptRunner Field Behaviour to force a Comment if the Due Date is changed

Karl Samson May 1, 2024

Hi All, I'm trying to implement a Field Behaviour, using ScriptRunner, that will mandate the Comment field, only when the Due Date is Changed. I'm also using a JEP custom field to record the date that the Due Date is changed. 

However, the current script I'm running doesn't seem to distinguish between when the Due Date field is edited or not, and just makes the Comment field mandatory for every Edit of the issues, which ideally is not what I want!?

Can anybody help me fix my code please?


import java.text.SimpleDateFormat
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

Issue issue = getUnderlyingIssue();

def dateField = getFieldByName("Due Date");
def commentField = getFieldById("comments");

   CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
   CustomField dateCustomField = customFieldManager.getCustomFieldObjectByName("Due Date");
   Timestamp dateCustomFieldTimestamp = issue.getCustomFieldValue(dateCustomField)!=null?(Timestamp)issue.getCustomFieldValue(dateCustomField):null;
   String dateCustomFieldValue = issue.getCustomFieldValue(dateCustomField)!=null? new SimpleDateFormat("MM/dd/yy").format(new Date(dateCustomFieldTimestamp.getTime())):"";
   String dateValue = dateField.value!=null?(dateField.value as Date).dateString:"";
   } else {

0 answers

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events