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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,458,351
Community Members
 
Community Events
176
Community Groups

How to set a custom field date (post function)

Hello, 

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")
cal.setTime(createdDate)

if(whenShouldRestoreCF == "1 week"){
cal.add(Calendar.HOUR,168)
endDateCF = cal.toMonthDay()
//log.warn(endDateCF)
}

if(whenShouldRestoreCF == "2 week"){
cal.add(Calendar.MONTH,336)
endDateCF = cal.toMonthDay()
}

if(whenShouldRestoreCF == "3 week"){
cal.add(Calendar.MONTH,504)
endDateCF = cal.toMonthDay()
}

 

 

1 answer

1 accepted

1 vote
Answer accepted

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

For setting custom fields, https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console 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() ) ){

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events