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

Error message upon selecting current date

Swarna Radha
Contributor
June 20, 2019

Hi,

I am using this script below:

// required import statements
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*
import com.atlassian.jira.issue.CustomFieldManager

CustomFieldManager customfieldmanager = ComponentAccessor.getCustomFieldManager()
def BOMdate_field = customfieldmanager.getCustomFieldObject('customfield_14403')

def BOMdate_val=issue.getCustomFieldValue(BOMdate_field) as Date

BOMdate_val.after(Calendar.getInstance().getTime())

 

The issue is that when i picked current date and I am getting error message.

 

Please advice.

Thanks,

Swarna

3 answers

1 accepted

0 votes
Answer accepted
Ilya Turov
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 20, 2019

i guess this is a way to work around today's date (replace your last row):

def startOfToday = Calendar.getInstance()
startOfToday.set(Calendar.MILLISECOND, 0)
startOfToday.set(Calendar.SECOND, 0)
startOfToday.set(Calendar.MINUTE, 0)
startOfToday.set(Calendar.HOUR_OF_DAY, 0)
!BOMdate_val.before(startOfToday.getTime())
Swarna Radha
Contributor
June 20, 2019

Hi IIya,

Thanks a lot,

It is now working :)

Thanks,

Swarna

0 votes
Ilya Turov
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 20, 2019 edited

if the customfield has no value in it BOMdate_val will be null and you won't be able to invoke the .after method on it

you can avoid it by safe navigation:

BOMdate_val?.after(Calendar.getInstance().getTime())

in this case if BOMdate_val is null, whole construction will return null (which is considered false in this case)

Swarna Radha
Contributor
June 20, 2019 edited

Hi IIya,

 

It is the same. Error message is being displayed. Please see screenshot.

 

Thanks

SwarnaScreenshot_3.png

Ilya Turov
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 20, 2019

well, it just means that the validator you created works correctly. it doesn't allow you to select the date that is greater than NOW. and your field type is Date, so it's stored as 00:00 of a day you selected, while Calendar.getInstance().getTime() is also current time, which is always later than the start of day.

0 votes
brbojorque
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 20, 2019

Hi @Swarna Radha , 

Would you mind showing the full stack trace of the error so we can troubleshoot further.

Swarna Radha
Contributor
June 20, 2019

How to perform a full stack trace?

Suggest an answer

Log in or Sign up to answer