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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cloud ScriptRunner Date Custom Field Validator

 

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!

1 answer

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

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'

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

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?

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

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!

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 Z B likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

4,556 views 12 8
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you