Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Only set custom field if null [Script Runner]

Emily B_ August 24, 2020

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))

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2020

Hi @Emily B_ 

You are checking if the field exists or not. You need to further check the value in that field.

Try this method.


I hope it helps.


0 votes
Emily B_ October 7, 2020

Spot on, replacing the variable with this within the If statement worked like a dream. Thank you!

AUG Leaders

Atlassian Community Events