Javascript-calculated custom field: Dealing with two dates

Hi guys,

I’m trying to create a Javascript-calculated custom field that checks if A date is before B date.

The field should create a dimension with Yes/No values so it should look like the following in the formula:

[Completed before Publish date].[Yes]
or
[[Completed before Publish date].[No]

Can anyone provide a specific code for that function?

Thank you!

Hi @Kyung_Park,

In Import options, you can create a new calculated field (Account specific calculated fields).

  1. Chose the data type “Sting” as results would be tests Yes / No

  2. Select the field for data import as “Dimension” so you can group and filter data by end results.

  3. In the JavaScript field, enter the code to compare dates. The logic would be tist to check if issieu has both dates and only then compare them. The code might look like this:

     // Check if both dates exists
     if (issue.fields.customfield_CCCCC && issue.fields.customfield_PPPPP) {
       // Parse dates into timestamps for comparison
       let completedDate = Date.parse(issue.fields.customfield_CCCCC);
       let publishDate = Date.parse(issue.fields.customfield_PPPPP);
       
       // Compare dates and return appropriate value
       if (publishDate >= completedDate) {
         return "Yes";
       } else if (completedDate > publishDate) {
         return "No";
       }
     }
    

    In the code example update the customfield_CCCCC and customfield_PPPPP with custom field ID that are holding the dates.

  4. I recommend testing the code on individual issues, one for each outcome.

On the Cloud and starting eazyBI version 8.0 (which will be released soon), an AI assistant can help you write JavaScript code.
Here are more details on how to work with eazyBI AI assistants: AI Assistants

Best,
Zane / support@eazyBI.com

Hi @zane.baranovska

This is exactly what I needed! Thank you so much!!

1 Like