ConfiForm: How to populate a date interval using definition rules

hoelzlw
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 8, 2020

I'm running Confluence 7.4.0.

I want to accomplish the following: A form, where users can either pick a single date, or a date interval. Then, present the data in a calender. Should be easy, but turns out that I wasted half a day without getting anywhere.

I want date intervals to be shown as intervals in the calender, so a possible solution would be to use the field type 'Datetime interval' and, for the single date events, use the start date as the end date.

The solution I thought of has two fields of type 'Date': date0 and date1. Then I tried to use definition rules to populate a further field of type 'Datetime interval' called date2. When date1 would be empty, date0 is written in both entries of date2. If date1 holds any value, I would write date0 and date1 into date2 as start and end.

I would hide date2 in the input form, but use its values afterwards.

 

According to the documentation, the proper field values in date2 are date2.startDate and date2.endDate.

However, it seems to be impossible to write anything into a field of type datetime interval.

 

Have a look at the following definitions:

<ac:structured-macro ac:macro-id="f1b70e5e-012e-497a-ad78-9e7e0c266a6e" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">date0</ac:parameter>
<ac:parameter ac:name="fieldLabel">Von</ac:parameter>
<ac:parameter ac:name="extras">dd.MM.yyyy</ac:parameter>
<ac:parameter ac:name="type">date</ac:parameter>
<ac:parameter ac:name="required">true</ac:parameter>
</ac:structured-macro>

<ac:structured-macro ac:macro-id="c60d935d-6b11-4463-980e-e4a493f13906" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">date2</ac:parameter>
<ac:parameter ac:name="fieldLabel">Von - Bis</ac:parameter>
<ac:parameter ac:name="values">0</ac:parameter>
<ac:parameter ac:name="extras">dd.MM.yyyy</ac:parameter>
<ac:parameter ac:name="type">datetimeinterval</ac:parameter>
</ac:structured-macro>

<ac:structured-macro ac:macro-id="91bbcdfc-17d2-4f29-9d8a-bee70ec84ada" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">!date0:[empty]</ac:parameter>
<ac:parameter ac:name="values">date2.startDate=[entry.date0]&amp;date2.endDate=[entry.date0]</ac:parameter>
<ac:parameter ac:name="action">Set value</ac:parameter>
<ac:parameter ac:name="actionFieldName">date0</ac:parameter>
</ac:structured-macro

All the code tries to do is: If date0 changes and if it isn't empty, write its content into start and end of the datetime interval.

But it simply doesn't do anything at all.

What am I missing here? How can I properly populate the values of the datetime interval?

 

Note that if I replace the datetime interval with two single date fields, everything works like a charm:

<ac:structured-macro ac:macro-id="4c85eee7-62cf-4196-a77c-845a691db46b" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">a</ac:parameter>
<ac:parameter ac:name="fieldLabel">b</ac:parameter>
<ac:parameter ac:name="extras">dd.MM.yyyy</ac:parameter>
<ac:parameter ac:name="type">date</ac:parameter>
</ac:structured-macro>

<ac:structured-macro ac:macro-id="aa120788-f70d-45e6-aeb5-482ab0dccca8" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">c</ac:parameter>
<ac:parameter ac:name="fieldLabel">d</ac:parameter>
<ac:parameter ac:name="extras">dd.MM.yyyy</ac:parameter>
<ac:parameter ac:name="type">date</ac:parameter>
</ac:structured-macro>

<ac:structured-macro ac:macro-id="c049704f-a8e3-404e-b1bc-4519319eb5bc" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">!date0:[empty]</ac:parameter>
<ac:parameter ac:name="values">a=[entry.date0]&amp;c=[entry.date0]</ac:parameter>
<ac:parameter ac:name="action">Set value</ac:parameter>
<ac:parameter ac:name="actionFieldName">date0</ac:parameter>
</ac:structured-macro>

 

This has to do with datetime interval, but I cannot figure out what.

1 answer

1 accepted

1 vote
Answer accepted
Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 9, 2020

The format expected by the date time interval field is the interval given as 2 timestamps separated by -

date2=[entry.date0]-[entry.date0]

However this does not make much sense as you will have a "zero" length interval where the start date is the same as end date

hoelzlw
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 9, 2020

Thank you, now it works perfectly.

Regarding the zero length interval: this denotes a single day. It doesn't look like the interpreter really subtracts two number here, but rather creates a string and parses it into an interval type.

This should be part of the documentation, imho.

Matthew Fulton April 23, 2021

Is this how you would map a datetime interval field to a Jira date field? I have a ConfiForm that has a datetime interval time field and Jira does not have a similar field type. Would you just map the confiform field to a two different JIRA date picker fields like this:

Period Start - "customfield_1111": "[entry.dateinterval.startDate.escapeJSON]",

Period End - "customfield_2222": "[entry.dateinterval.endDate.escapeJSON]",

Alex Medved _ConfiForms_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2021

Dates in Jira REST API are expected to be in yyyy-MM-dd format

So, it will be something like:

[entry.dateinterval.startDate.jiraDate]

 or

[entry.dateinterval.startDate.formatDate(yyyy-MM-dd)]

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events