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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Only set custom field if null [Script Runner]

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

1 vote
Answer accepted

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.


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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Jira Cloud Performance Improvements

Hello everyone, I am a product manager in the Jira Cloud team focused on making sure our customers have a delightful experience using our products. Towards that goal, one of the areas which is extr...

184 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you