How to put a condition on the date field before the issue created

CRS123456 June 18, 2022

Hello,

Thanks for your excellent website.

I'm a Jira-service desk supporter.

I have got a project definition issue type and in this issue type, I've got a date picker field that has the Project Plan Delivery Date name. but I want to put a condition on this field for users can't pick a date for more than 2 months.

Also, I have "Adaptavist ScriptRunner for JIRA" but don't know how to write scripts.

I appreciate your help.

 

1 answer

1 accepted

0 votes
Answer accepted
CRS123456 June 18, 2022
import org.apache.xpath.operations.Minus
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*

// Get pointers to my date field and get its value as a date
def cf = getFieldByName("userdate")
def cfval = cf.getValue() as Date
if(cfval > 60) {
fieldScreen.print("Please enter a day less than 60 days")
}else{
fieldScreen.remove()
}

I searched some things but don't know if this code is right or not. Can anyone help me, please?
Marcin Wiktor
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.
June 19, 2022

You should edit your workflow, and on a specific transition, you can add a "Validator" that is called "Date Compare Validator"

Bez tytułu.png

CRS123456 June 19, 2022

Thank you @Marcin Wiktor 

I know this way but this is for when I created the issue.

I want something before the creation so as a result, I don't have workflow before the creation.

Marcin Wiktor
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.
June 19, 2022

@CRS123456 but you can add this validator on a "create issue" path (literally the path that goes as first in your's workflow) - it will prevent people from createing an issue when this condition isn't match.

Like # people like this
CRS123456 June 19, 2022

@Marcin Wiktor 

You're right. I didn't know this so I learned a new thing.

It's working great, man. Thanks a lot. 

Capture.JPG

Suggest an answer

Log in or Sign up to answer