JMCF scripted duration field doesn't work

Alexander Makarovsky September 19, 2024

 

Calendar calendar = Calendar.getInstance(); while (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { calendar.add(Calendar.DATE, -1); } currentWeekMonday = calendar.getTime().clearTime(); timeItems = issue.getFieldHistory("timespent").findAll({ it.created >= currentWeekMonday }); return timeItems.sum(0, { it.from ? it.to.toInteger() - it.from.toInteger() : it.to.toInteger() })/3600;

Hi! I've created JMCF duration field and used groovy formula to estimate amount of time spent during current week. When testing the formula in field configuration everything works fine, but on issue page the field shows zero, like the script is not executed of something. What am I doing wrong?

1 answer

0 votes
Javier Martínez Caballero
Contributor
October 22, 2024

Hi @Alexander Makarovsky

It sounds like the script is working well during testing but not executing properly on the issue page. This could be due to several reasons:

  1. JMCF Field Context and Execution Scope: Make sure the JMCF field is configured for the specific project or issue types where it’s being used. If the field isn’t set up for the right context, it might not be executing on the issue page.

  2. Script Execution Timing: Check if the script is set to run during the issue view context. JMCF allows for different execution timings (issue create, update, view, etc.), and the script might not be running when the issue page is viewed.

  3. Field History Availability: It’s possible that the timespent field history is not available or fully loaded when the issue page is being viewed. You can add logging to the script to check if the timeItems list is empty at that time:


    log.debug("Current Week Monday: ${currentWeekMonday}")
    log.debug("Time Items: ${timeItems}")

  4. Caching or Data Refresh: Sometimes, field values don’t immediately update due to caching. Try re-indexing the issue or clearing any caches to see if that helps.

  5. Permissions: Ensure that the user viewing the issue has permission to access the field history (timespent). Without the proper permissions, the field may not show any values.

These troubleshooting steps should help identify the cause of the issue. If it persists, running the script in Jira’s Script Console (if available) can help with further debugging.

Let me know how it goes!

Best regards,
Javier

Alexander Makarovsky October 22, 2024

Hi! I've resolved it but can't remember the exact solution.
thanks anyway!

Suggest an answer

Log in or Sign up to answer