Cloud ScriptRunner Date Custom Field Validator

Zita Bagi
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.
January 27, 2021

 

I have a question about validating date customfield in Cloud.
this:
new Date(issue.customfield_10061).toISOString() > new Date().toISOString()
Still gives an error:
Evaluation failed: "new Date(issue.customfield_10061)" - The date has invalid format. Expected: ISO-8601, for example: 2011-12-03T10:15:30

I tried different versions:
//new Date(issue.customfield_10061).toCalendarDate("yyyy-MM-dd") > new Date().toCalendarDate("yyyy-MM-dd")
//(new Date(issue.customfield_10061).format("yyyy-MM-dd'T'HH:mm:ssZ")) > new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
//new Date(issue.customfield_10061).format("yyyy-MM-dd'T'HH:mm:ssZ", TimeZone.getTimeZone("UTC") > new Date().format("yyyy-MM-dd'T'HH:mm:ssZ", TimeZone.getTimeZone("UTC")

But I keep getting this same error message.
Can you please let me know how to parse a date custom field so taht it would be ISO-8601, if not with .toISOString()?

Thank you!

3 answers

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 27, 2021

Hi Z B,

Thank you for your question.

I can confirm that the reason why you are getting the error is due to the fact that your code for the Workflow Validator is not valid code and I can confirm that Workflow Validators are defined using the Jira Expression Framework as documented in the Atlassian API documentation page located here  or in the documentation page located here  which explains how to add in a new validator to your workflow.

In your condition, you are writing Groovy Code which is not valid when defining Conditions or Validators inside of Jira Cloud and this is the reason why you are seeing the error which you are seeing.

We can confirm that when viewing the Jira Expression Framework API documentation page linked above you can navigate to the Context variables section which shows what variables are provided by this framework that can be used to create the expression.

If you then click on one of the variables it will show all the properties that can be called on the variable for the expression such as for the issue variable as shown here and you will be able to check this to see if Atlassian provides a variable that can be checked against to help create the validator which you require.

I am unable to provide an exact expression to achieve your requirement as our support process does not cover writing expressions or scripts, but you can use the resources shared above as a reference guide to help create that validator expression which you require.

I hope this information helps.

Regards,

Kristian

Zita Bagi
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.
January 28, 2021

Thanks for letting me know that it was groovy and that you cannot actually help.

So I guess this is an expression:

issue.customfield_10061 > issue.created

But issue.customfield_10061  comes as a string, how can I parse it into a date?

When I try  

issue.customfield_10061.toCalendarDate() 

or

issue.customfield_10061.toISOString()

also don't work, I get this error msg:

Evaluation failed: "issue.customfield_10061.toCalendarDate" - Unrecognized property of `issue.customfield_10061`: "toCalendarDate" ('toCalendarDate'). Available properties of type 'String' are: 'includes', 'indexOf', 'length', 'match', 'replace', 'slice', 'split', 'toLowerCase', 'toUpperCase', 'trim'

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2021

Hi ZB,

Please note that my response was designed to help yourself and I apologise if you feel I am not helping yourself.

I can confirm that if the field is a string then Atlassian will not allow this to be parsed to a date in the expression framework that they provide in Jira cloud as they only allow the methods which they document here to be called on string fields. 

This, unfortunately, means that it is not possible to parse the value of the field to date as Atlassian does not allow this in Jira cloud as they do not provide any methods to do this and this caused by the differences in the API's between Jira Cloud and Jira Server.

Unfortunately, this means that it is not possible to achieve your requirement due to the reasons explained above.

Regards,

Kristian

Zita Bagi
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.
January 28, 2021

My custom field is a date picker, but in the validator it says it's a string. Is this normal (referring to what you said about limitations) or am I just doing it wrong?

Also in the site you referenced I can see that I can get 

issue.customfield_10061

 and I'm not sure why I cannot call toISOString() here, if this is a date picker field. The error msg says I'm only allowed to call what'd available for prototype string. Is this the limitation you are mentioning or am I trying to get the value incorrectly?

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2021

Hi ZB,

I believe this a limitation of the expression framework if it is not recognising the field correctly.

As it is Atlassian who produce the expression framework, then I would be raising a support ticket with them as they will be able to confirm if there is any other way to do this. 

I can confirm there are methods that can be called on a date field as documented here and these should be able to be called if the field is recognised as a date field but I would ask Atlassian to confirm why these cannot be called.

Regards,

Kristian

Zita Bagi
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.
January 28, 2021

Yes, I understand the methods can be called on the date fields, but I'll definitely need to call these on date custom fields too.

Do you mean you are going to / have raised such a ticket with Atlassian? Can I be added as a request participant? Or should I raise it somewhere? Or is there any further documentation where this question can be answered?

Also, I know there is this  https://scriptrunner-docs.connect.adaptavist.com/jiracloud/migrating.html#_migrating_from_scriptrunner_for_jira_server_to_cloud but is there a roadmap for Scriptrunner where dates are provided about which feature would be ready by when?

Thank you for all the info you are providing, this all still makes me understand Cloud Scriptrunner a little better!

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 28, 2021

Hi ZB,

I meant that you will need to raise a ticket with Atlassian which you can do here as the Jira Expression Framework is provided by Atlassian.

I can confirm we have a public backlog here where you can suggest features that you are interested in but we do not have any dates on when we will have the same features as the server version that we can share.

Regards,

Kristian

Like Zita Bagi likes this
0 votes
Teri Michaels December 12, 2023

Just had this same issue and found a resolution by adding the time part of the date to the Time Picker custom field. Ex: 
new Date(issue.customfield_10061 + 'T00:00:00+07:00').toCalendarDate() > new Date().toCalendarDate()

0 votes
Andrey Permyakov December 13, 2021

@Z B 

Hi

Were you able to resolve your request?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events