Hey guys,
I'm still learning how to write custom scripts using Script Runner for Jira server, and I'm having trouble finding documentation to help me with this one: I am trying to only set a custom field to the current date/time (timestamp) if it is currently empty (null). If there is already a value set, no action should occur. I'm not getting any errors, and the post function runs without issue, but it's not posting the timestamp as expected. Any ideas?
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//declare variable
def cfcomplete = customFieldManager.getCustomFieldObjectByName("DevCompleteDtTm") //Set custom text field with current date & time if blank
if (cfcomplete == null) {
issue.setCustomFieldValue(cfcomplete, new Timestamp(new Date().time))
}
Hi @Emily C.
You are checking if the field exists or not. You need to further check the value in that field.
Try this method.
issue.getCustomFieldValue(cfcomplete)
I hope it helps.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.