How to determine Field Type of Scripted Field

Hello,

 

I am running JIRA 7.2.4 and Adaptavist Scriptrunner for JIRA 4.3.15.

 

While writing a Gadget Plugin, i wanted to place a DateField picker, where you can chose a DateField that shall be used for displaying something. I figured Jira has an already built in REST interface with: /rest/gadget/1.0/dateFields to get all DateFields. The Problem is, that the ScriptedFields have a different CustomFieldType than DateField (CustomGroovyField).

I do have some scripted fields that have date picker as search template where they calculate their dates from other data, so they are basically date fields but they are not derived from DateField.

 

For now I copied the REST interface and manually add them to the list (by name). Is there a generic way to determine the underlying type of a scripted field, or any other more elegant solution to this problem?

 

Example:

for (final Field field : navigableFields) {
    if (isDateTypeField(field) || field.getName().equals("Currently planned begin")) {
       fields.add(new DateFieldBean(field.getId(), field.getName()));
   }
}

 

1 answer

0 vote
Micky Caritte Community Champion Nov 29, 2017

Hi,

I would recommend you to use the RegEx groovy feature :)

boolean match = "2010.12.12" ==~ /\d{4}\.\d{2}\.\d{2}/

This would work if your date custom fields are formatted in such a way you can find an associated regular expression. If you are not familiar with regular expressions, internet will help you finding the associated regex to match your needs, a good example is here: http://www.regexlib.com/Search.aspx?k=date

Your script can therefore be updated to check either isDateTypeField or  (CustomGroovyField + matching pattern).

Hope this helps!

I had that thought before. The thing is, I need a list of all fields that can hold dates, which means they don't necessarily have content that can be processed through regex checks. That's why I need information about the type as I can't always expect it to have content.

There's a slight problem there - the "type" of a scripted field is "a scripted field"

There's nothing ScriptRunner can do about this, and not a lot Jira can either - it's the way Jira has to handle custom field types.

Your only option over REST is to check if the content returned looks like a date.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,345 views 14 20
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot