One date field should be future date to the other date

Arunajyothi Samala March 4, 2024

Hi,

 

I have two custom date fields i.e., Target start date and Target end date. Target end date should be future should to Target start date on all screens.

How to achieve this?

Pluggings: SIL and ScriptRunner available

2 answers

1 accepted

0 votes
Answer accepted
Sean Chua _Adaptavist_ March 5, 2024

Hi @Arunajyothi Samala , Hope you are doing well. I assume that you are looking to ensure that on Create or Issue Edit, Target End > Target Start Date.

With ScriptRunner for Jira Data Center, you can do this with Behaviours. Here is a sample script which works, but you will need to make changes to match your Jira Instance's Custom Field : ScriptRunner Jira DC - Behaviours (Date Picker Field B > Date Picker Field A) 

It is relatively straight forward but if there are any issues, do feel free to open a support ticket with us from ScriptRunner.

Regards,
Sean

Arunajyothi Samala March 5, 2024

Hi @Sean Chua _Adaptavist_ ,

I tried your solution as intialiser script from but it doesn't prevent the user for creating an issue with end date before start date. audit logs show it got excuted but didn't restrict the creation of the issue.

I observed that the first two variables defined with object command were never used, could you please let me know if I did anything wrong. 

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
@BaseScript FieldBehaviours fieldBehaviours

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def targetStartDateField = customFieldManager.getCustomFieldObject( 19803 )
def targetEndDateField = customFieldManager.getCustomFieldObject( 22638 )

def targetStartDate = getFieldById("customfield_19803")
def targetEndDate = getFieldById("customfield_22638")

def startDate = targetStartDate.getValue() as Date
def endDate = targetEndDate.getValue() as Date

if (startDate && endDate && endDate.before(startDate)) {
    targetEndDate.setError("Target End must be in the future of Target Start.")
} else {
    targetEndDate.clearError()
}
Sean Chua _Adaptavist_ March 5, 2024

Hi @Arunajyothi Samala ,

Thanks for getting back to me. Based off the script alone, I am unsure why it doesn't work for you. There could be other reasons, so while straightforward, wouldn't hurt for you to open a support ticket with us to investigate with our support engineers.

Just to show you that mine doesn't allow me to create a ticket or save the edit issue changes when the Target End is before Target Start. I'm using ScriptRunner for Jira DC v8.18.


image.png

The Custom field type are "Date Picker";

image.png

Regards,
Sean

Arunajyothi Samala March 15, 2024

Yes @Sean Chua _Adaptavist_ Both are data pickers. Sorry little busy with deployments, couldn't get back to you on time. I tried the other way around, instead of intialiser , I tried two fields with server side scripts using fieldIdchanged function. that scripts are working fine. Thank you.

1 vote
Reshma Begum _Appfire_
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.
March 5, 2024

Hi @Arunajyothi Samala ,

With SIL, you can add a validator script as below to check if the target end date is always greater than the target start date on a transition screen.

if(getInput("customfield_10801") < getInput("customfield_10800"))
{
return false;
}

 Hope this helps!

BTW, I am Reshma from Appfire, a vendor of SIL Engine and Power suite apps.

Thanks,

Reshma

Suggest an answer

Log in or Sign up to answer