How do I modify the ConfiForm date to the format needed by JIRA

Chris_Stewart November 16, 2017

I'm creating a form using ConfiForms to create a JIRA task. Here is the code that I currently have located in a IFTTT to create JIRA Issue. Then a No Format macro inside of that, which contains the following code:

{

  "fields": {
     "project":
     {
     "key": "TASK"
     },
     "summary": "[entry.summary]",
     "description": "[entry.details]",
     "issuetype": { "name": "Task" },
     "assignee": { "name": "[entry.user]" },
     "customfield_20721": [{"id":"[entry.categories]"} ],
     "duedate":"[entry.duedate]
  }
}

This code worked perfectly when the duedate was manually entered (coded date) with the expected format ("duedate":"2012-10-10" ). Unfortunately, the format that confiForms is passing through is MMM dd, yyyy; which causes a "Could not prepare JSON..." error. 

 

Q: How can I change the format from MMM dd, yyyy to the format that JIRA is expecting: yyyy-MM-dd?

3 comments

Comment

Log in or Sign up to comment
Chris_Stewart November 20, 2017

In case someone else comes across this issue. The solution was: "duedate":"[entry.duedate.jiraDate]"

Note:
The first "duedate" is the JIRA field that the data will go to.

The duedate in the [entry.duedate...] is the name of my confiform field that the data is being pulled from. 

I probably should not have named my form field the same as the JIRA field.

Alex Medved _ConfiForms_
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 28, 2018

Please look at Virtual functions in ConfiForms. We have some helper functions for exactly your needs

jiraDate

Same as "formatDate" method above, but specifies constant dateformat pattern (yyyy-MM-dd), suitable for JIRA REST API

 

jiraDateTime

Same as "formatDate" method above, but specifies constant dateformat pattern ("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), should be compatible with ISO 8601 standard as JIRA requires when setting timestamps to JIRA fields

Like Chris_Stewart likes this
VLIZ Software September 28, 2018

This helper function is not available in the filter.action? How can I retrieve another date format than the double when using the search function of the REST api?

Alex Medved _ConfiForms_
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.
October 1, 2018

You can specify the "fields" parameter in REST API call as described here https://wiki.vertuna.com/display/CONFIFORMS/REST+API#RESTAPI-Searchentries to decorate/transform the field value as needed (with virtual functions)

VLIZ Software October 1, 2018

Thanks Alex, it works.

Elavrasi April 25, 2019

Hi Alex ,

Is the "fields" parameter in REST API call applicable only to search entries ? shall we use it in create entry REST API call ? will it work ?

Alex Medved _ConfiForms_
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.
April 25, 2019

Not sure I understand the question here, sorry... the format for the JSON is based on the spec given by Atlassian.

 

https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

 

This is where this "fields" node comes from

Elavrasi April 27, 2019

Hi Alex,

my question is as per below link we can use fields parameter in REST API for searching entries in confiforms. so is it possible to use the fields parameter to create an entry ?

 https://wiki.vertuna.com/display/CONFIFORMS/REST+API#RESTAPI-Searchentries 

Alex Medved _ConfiForms_
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.
May 6, 2019

Sorry, I dont quite understand... you refer to the API that helps you to search ConfiForms entries - how is this connected to "create and entry"? Creating an entry can be done using this API - https://wiki.vertuna.com/display/CONFIFORMS/REST+API#RESTAPI-Createentry

SP May 11, 2020

I have same issue.

 

JIRA DATE Format: '2020-05-12T17:36:00.000-0500'

Confiform date: entry.TestDate.jiraDateTime

 

Tried format: entry.TestDate.formatDate(yyyy-MM-dd'T'HH:mm:ss.SSSZ) ( Actual time is May 12, 2020 01:30 )

JIRA output: 11/May/20 8:30 PM

Alex Medved _ConfiForms_
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.
May 11, 2020

So in the mapping  you need to set this as 

"some_jira_datetime_field":"[entry.TestDate.jiraDateTime] 

 Assuming you have "TestDate" as a date/datetime field in ConfiForms 

SP May 12, 2020

I tried that one but didn’t help

SP May 12, 2020

In confiform I set field as datetime 

Alex Medved _ConfiForms_
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.
May 12, 2020

OK, and what is the problem? You have mentioned you are having the same issue, but what exactly is your issue? 

I see the time difference in your examples and that might be the difference in timezones you have for Confluence/Jira. Or the differences in how your profiles are set in Confluence /Jira and if they use the same "timezone"

SP May 12, 2020

am in central timezone.


Issues is the time which am choosing in confiform is central timezone but when I send to jira the time got change.

But when I am doing manually in jira I cloud see datetime in cst 

Alex Medved _ConfiForms_
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.
May 12, 2020

And you servers have different time? Are they in a different timezone?

SP May 12, 2020

Yes

Alex Medved _ConfiForms_
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.
May 12, 2020

And that time differs from your time 7 hours?

SP May 12, 2020

Confluence 

system timezone etc/utc 

 

jira

time zone gmt-06:00 chicago

Alex Medved _ConfiForms_
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.
May 12, 2020

And this is the answer, right? That is why you see a different time in Jira (compared to Confluence)

SP May 12, 2020

is that possible to format datetime ? 

Alex Medved _ConfiForms_
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.
May 12, 2020

Where? Where do you want to format datetime? In ConfiForms?

Yes, we do have various functions, including the one to formatDate (and time)

https://wiki.vertuna.com/display/CONFIFORMS/Virtual+functions

SP May 12, 2020

confiform, is there any way to substract time in formatDate? like -86400000 milliseconds

SP May 12, 2020

"date_field": "[entry.TestDate.formatDate(yyyy-MM-dd'T'HH:mm:ss.SSSZ)]" is that possible to do changes here for my requirement.

Chris_Stewart May 12, 2020

I’ve used the following in some of my projects to add or subtract time:

[entry.somedatefield.timestamp.add(86400000)]

to subtract just add a “-“ sign in front of the milliseconds.

this can be found on the Virtual Functions page Alex mentioned above by searching “add(number)”. It’s a very useful page.

Alex Medved _ConfiForms_
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.
May 12, 2020

Yes, that's right. Thanks @Chris_Stewart 

Then something like this:

[entry.somedatefield.timestamp.add(-86400000).jiraDateTime]

SP May 12, 2020

[entry.somedatefield.timestamp.add(-86400000).jiraDateTime] - worked

Thanks @Alex Medved _ConfiForms_ and @Chris_Stewart 

TAGS
AUG Leaders

Atlassian Community Events