Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

When user changes field, force Comment on Save (or upon field entry) not on Transition

Kathy Dickason
Contributor
March 24, 2026

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

2 answers

1 accepted

2 votes
Answer accepted
Nikola Perisic
Community Champion
March 24, 2026

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)
Kathy Dickason
Contributor
March 24, 2026

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.

 

Nikola Perisic
Community Champion
March 24, 2026
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. 

Kathy Dickason
Contributor
March 24, 2026

(no comment)

Kathy Dickason
Contributor
March 24, 2026

Just saw your answer above this. I will try that now.

Kathy Dickason
Contributor
March 24, 2026

Thank you!!!!!!

Like Nikola Perisic likes this
Nikola Perisic
Community Champion
March 24, 2026

You are welcome @Kathy Dickason !

0 votes
Kathy Dickason
Contributor
March 24, 2026

That did it!  You're wonderful!!!!!

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
10.3.8
TAGS
AUG Leaders

Atlassian Community Events