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

How to set a custom field date (post function)

Gökberk Karaca March 30, 2022


So I want to set the custom field date to a certain time after the created date, depending on the condition. For example, if i choose "1 week" from the dropdown list, my "end date" custom field should be set to the date after issue's created date. I cant figure out what the problem is. Can you please help me? Thanks.  Here is a part of my code: 

def createdDate = issue.getCreated()
def whenShouldRestoreCF = customFieldManager.getCustomFieldObject("11335")
def endDateCF = customFieldManager.getCustomFieldObject("11334")

if(whenShouldRestoreCF == "1 week"){
endDateCF = cal.toMonthDay()

if(whenShouldRestoreCF == "2 week"){
endDateCF = cal.toMonthDay()

if(whenShouldRestoreCF == "3 week"){
endDateCF = cal.toMonthDay()



1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 30, 2022

Your script is not actually trying to set the field, and I don't think your "if" statements are right.

For setting custom fields, is my go-to reference, you'll be able to see how to set your value from that.

The if statement problem I see is that whenShouldRestoreCF will contain an option, not a string, if the field is a select list.  If it is, I would try:

if( "1 week".equals(whenShouldRestoreCF.getName() ) ){

AUG Leaders

Atlassian Community Events