Scripted Custom Field HTML Table Issues

Hi,

I have a scripted field that is simply returning an HTML string.

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.util.JiraDurationUtils
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.info("Starting GroovyScript ProjectBudgetOverviewcalcualtor")
MutableIssue issue = issue

if(issue.getStatusObject().getName().equals("Proposed")){
    TimeTrackingConfiguration timeTrackingConfiguration = new TimeTrackingConfiguration.PropertiesAdaptor(ComponentAccessor.getApplicationProperties())
    def hoursPerDay = timeTrackingConfiguration.hoursPerDay
    def daysPerWeek = timeTrackingConfiguration.daysPerWeek
    Project project = issue.getProjectObject()
    def allIssueIds = ComponentAccessor.getIssueManager().getIssueIdsForProject(project.getId())
    def allIssues = ComponentAccessor.getIssueManager().getIssueObjects(allIssueIds)
    def projectBudgetASString = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Metadata - Project Budget"))
    def table = "<style type=\"text/css\">" +
            "table.tftable {font-size:10px;color:#333333;width:100%;border-width: 1px;border-color: #a9a9a9;border-collapse: collapse;}" +
            "table.tftable th {font-size:12px;background-color:#b8b8b8;border-width: 1px;padding: 8px;border-style: solid;border-color: #a9a9a9;}" +
            "table.tftable tr {background-color:#ffffff;}" +
            "table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #a9a9a9;}" +
            "</style>" +
            "<table class=\"tftable\">" +
            "<tr><th colspan=\"8\">Budget Overviews</th></tr>" +
            "<tr><td></td><td><b>Project</b></td><td>Project Management</td><td>Hardware</td><td>Software</td><td>Integration</td><td>Deploy</td><td>General Project Activity</td></tr>" +
            "<tr><td>Defined</td><td>DEFINED_PROJECT</td><td>DEFINED_PM</td><td>DEFINED_HW</td><td>DEFINED_SW</td><td>DEFINED_INT</td><td>DEFINED_DEP</td><td>DEFINED_GA</td></tr>" +
            "<tr><td>Σ Budgeted</td><td>BUDG_PROJECT</td><td>BUDG_PM</td><td>BUDG_HW</td><td>BUDG_SW</td><td>BUDG_INT</td><td>BUDG_DEP</td><td>BUDG_GA</td></tr>" +
            "<tr><td>Σ Time Spent</td><td>TIME_PROJECT</td><td>TIME_PM</td><td>TIME_HW</td><td>TIME_SW</td><td>TIME_INT</td><td>TIME_DEP</td><td>TIME_GA</td></tr>" +
            "<tr><td>Σ Remaining</td><td>REM_PROJECT</td><td>REM_PM</td><td>REM_HW</td><td>REM_SW</td><td>REM_INT</td><td>REM_DEP</td><td>REM_GA</td></tr>" +
            "</table>"
    return table

The code is not exactly complete but it is returning the HTML string ok. My issue is that when I refresh the issue that contains the field the rendereing of the table doesn't always work. It seems that it is showing different versions of the script as I test and develop it.

I don't know if this is a caching issue or the fact I am using CSS styles in my HTML string (it seems to work though). I have tried to clear the cache using one of the built in scripts. This didn't seem to work.

This is what I expect it to look like...

If I refresh the issue a few times I often get these views...

These seem to be previous versions of the script I am writing.

I have set the Scripted Field Template as HTML and Free Text Field, doesn't seem to make a difference. Interestingly the text in the top left "BLANK" doesn't exist in the HTML String, yet it still shows?! This is what leads me to believe I have a caching issue. I have tried Chrome, IE9 and Firefox, same results for all and I have tried clearing the browser cache.

If I continually refresh (F5) I can almost track the changes I have made! Is there a way of ensuring only the script on the server is called and not a cached one?

2 answers

1 accepted

There is a thread local cache... it will get updated when the issue is updated. I have never seen it display previous values though. Possibly they are values from a different thread, and everytime you refresh you go to a different thread, if you get a thread that you have used before you see the previous value.

You should use the preview functionality in admin -> scripted fields though, this disables the caching.

Also, you might want to consider using the idalko table grid plugin instead (or as well as scripting)...

Further testing shows this must be on the issue level, if I make a small change to the issue then the table is shown correctly everytime. So how can I ensure this is the case everytime? Can I clear issue cache somehow?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

335 views 0 1
Read article

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