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

Create a Validation of custom date field while creating the issue using scriptrunner

Hi All ,

 

I have a custom field "Target Implemintation Date" which is on the customer screen, I have created a validation on the create Transition that will compare the date it have to be more than 14 days in the future, otherwise it won't create the issue.

I used a "custom Script Validator" with the following code, but nothing happanes, please help.

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def targetDateField = customFieldManager.getCustomFieldObjectByName("Target Implementation Date")

def targetDate = issue.getCustomFieldValue(targetDateField)

if (targetDate) {
    def currentDate = new Date()
    def futureDate = currentDate + 14

    if (targetDate > futureDate) {
        return true
    }
}
else
{
error ("please change the date ro be at least 14 days in the future")
}

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 16, 2023

Hi @tamer_afifi 

 

First, I may suggest some changes in your code.

Don't use the getCustomFieldObjectByName() method as it's deprecated. Instead, you can use the below code to get the custom field by its ID value (simply replace 'xxxxx' with your custom field long ID value.

def targetDateField = customFieldManager.getCustomFieldObject("customfield_xxxxx")
In the else part of your code please use
throw new InvalidInputException("please change the date to be at least 14 days in the future")
I hope it helps

Suggest an answer

Log in or Sign up to answer