When a user updates a field (Due Date), I want to force them to add a comment on why they are making the update, either immediately when they change the field, or upon Saving the issue. I do not want to do this upon status transition.
I don't care if we pop up the Comment screen or simply instruct the user that they must add a comment.
I have Scriptrunner but I am unsure of the script to use.
I also have tried to do this via Automation, but other than inserting a generic comment, I see no way to make the user enter their specific comment in an Automation.
If Scriptrunner is the way to go, please if possible provide me the script I would use to force a comment screen to pop up or to tell the user they must enter a comment to save the issue.
Thank you
Hello @Kathy Dickason
This can be done with ScriptRunner behaviors, where you are adding the script to Due Date
import java.sql.Timestamp
import java.text.SimpleDateFormat
def dueDateField = getFieldById("duedate")
def commentField = getFieldById("comment")
// Current value in the form
def currentDueDate = dueDateField.getValue()
// Original persisted value from the issue before edit
def originalDueDate = underlyingIssue?.getDueDate()
// Normalize both values to yyyy-MM-dd for safe comparison
def fmt = new SimpleDateFormat("yyyy-MM-dd")
String currentStr = null
if (currentDueDate instanceof Date) {
currentStr = fmt.format((Date) currentDueDate)
} else if (currentDueDate instanceof Timestamp) {
currentStr = fmt.format(new Date(((Timestamp) currentDueDate).time))
} else if (currentDueDate) {
currentStr = currentDueDate.toString()
}
String originalStr = originalDueDate ? fmt.format(originalDueDate) : null
boolean dueDateChanged = currentStr != originalStr
if (dueDateChanged) {
commentField.setRequired(true)
commentField.setHelpText("You must add a comment explaining why the Due Date was changed.")
} else {
commentField.setRequired(false)
commentField.setHelpText(null)
}
Thank you so much for replying so quickly! One point of clarification. If the field is named "Next Milestone Due" how does your script above need to be modified? I must be doing something wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import java.text.SimpleDateFormat
def newMilestoneField = getFieldByName("New Milestone Due Date")
def commentField = getFieldById("comment")
// Current value in the form
def currentMilestoneDate = newMilestoneField.getValue()
// Original persisted value from the issue before edit
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def milestoneCf = customFieldManager.getCustomFieldObjectsByName("New Milestone Due Date")?.first()
def originalMilestoneDate = milestoneCf ? underlyingIssue?.getCustomFieldValue(milestoneCf) : null
// Normalize both values to yyyy-MM-dd for safe comparison
def fmt = new SimpleDateFormat("yyyy-MM-dd")
String currentStr = null
if (currentMilestoneDate instanceof Date) {
currentStr = fmt.format((Date) currentMilestoneDate)
} else if (currentMilestoneDate instanceof Timestamp) {
currentStr = fmt.format(new Date(((Timestamp) currentMilestoneDate).time))
} else if (currentMilestoneDate) {
currentStr = currentMilestoneDate.toString()
}
String originalStr = null
if (originalMilestoneDate instanceof Date) {
originalStr = fmt.format((Date) originalMilestoneDate)
} else if (originalMilestoneDate instanceof Timestamp) {
originalStr = fmt.format(new Date(((Timestamp) originalMilestoneDate).time))
} else if (originalMilestoneDate) {
originalStr = originalMilestoneDate.toString()
}
boolean milestoneDateChanged = currentStr != originalStr
if (milestoneDateChanged) {
commentField.setRequired(true)
commentField.setHelpText("You must add a comment explaining why the New Milestone Due Date was changed.")
} else {
commentField.setRequired(false)
commentField.setHelpText(null)
}
This should be the modified script then. For the field, you need to find your Next Milestone Due. Before that, it needs to be added to your screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just saw your answer above this. I will try that now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.