I have script created via script runner fragment option which is used to filter the values using drop down with certain custom fields (Team,Iteration) the script is working fine before upgrade of my Jira 9.4.1 I am using java script inside my groovy script for filtering
filter is now working on the same wepanel refer the attached screen shot same filter is not working when I open the page in a new tab can anybody help me to fix this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue
import groovy.xml.MarkupBuilder
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.rm.teams.api.team.GeneralTeamService
import com.atlassian.rm.teams.api.team.Team
@WithPlugin("com.atlassian.teams")
@PluginModule GeneralTeamService teamService
def envURL = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def teamCustomField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_13674")
def parentLinkField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_13675")
def piCustomField, iesIterationField, estFeatureSizeField,radioButton
piCustomField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_19277")
iesIterationField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_19298")
estFeatureSizeField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_17570")
radioButton= ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_19870")
}
piCustomField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_15877")
iesIterationField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_15975")
estFeatureSizeField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_15570")
}
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def jiraAuthenticationContext = ComponentAccessor.getComponent(JiraAuthenticationContext)
def user = jiraAuthenticationContext.loggedInUser
def query = jqlQueryParser.parseQuery("type = Epic AND cf[$piCustomField.idAsLong] = $context.issue order by cf[$iesIterationField.idAsLong] asc")
def searchCount = searchService.searchCount(user, query)
def searchResults = searchService.search(user, query, PagerFilter.unlimitedFilter)
def issues = searchResults.results.collect { ComponentAccessor.issueManager.getIssueObject(it.id) }
def output = new StringWriter()
def html = new MarkupBuilder(output)
def epicLink = "Epic-Story Link"
def toDoCount = issues.count { it.status.statusCategory.name == "New" }
def inProgressCount = issues.count { it.status.statusCategory.name == "In Progress" }
def completedCount = issues.count { it.status.statusCategory.name == "Complete" }
def allTeams = [0:"All"]
allTeams.putAll(issues.collectEntries {
def teamV = it.getCustomFieldValue(teamCustomField) as Team
return [teamV? teamV.id : "Empty", teamV ? teamV.description.title : "Empty"]
})
def piIterationVals = [] as Set
piIterationVals.add("All")
piIterationVals.addAll(issues.collect {
return it.getCustomFieldValue(iesIterationField)? it.getCustomFieldValue(iesIterationField) : "Empty"
})
def allStatus= [] as Set
allStatus.add("All")
allStatus.addAll(issues.collect {
return it.getStatus().name ? it.getStatus().name : "Empty"
})
html.div(id:"featuresPI") {
script(type:"text/javascript") {
html.mkp.yieldUnescaped("""
\$(function(\$) {
var report = AJS.\$("#featuresPI");
AJS.\$("#featuresPISelect").auiSelect2();
AJS.\$("#iterationSelect").auiSelect2();
AJS.\$("#statusSelect").auiSelect2();
var totalElem = report.find("#featuresPISearchCount");
var completedElem = report.find("#featuresPICompletedCount");
var inProgressElem = report.find("#featuresPIProgressCount");
var notStartedElem = report.find("#featuresPIToDoCount");
var oTotalValue = totalElem.text();
var oCompletedValue = completedElem.text();
var oInProgressValue = inProgressElem.text();
var oNotStartedValue = notStartedElem.text();
report.find("#featuresPISelect").change(function() {
doFilter();
});
report.find("#iterationSelect").change(function() {
doFilter();
});
report.find("#statusSelect").change(function() {
doFilter();
});
function doFilter() {
var filter = report.find("#featuresPISelect")[0].value;
var filter2 = report.find("#iterationSelect")[0].value;
var filter3 = report.find("#statusSelect")[0].value;
report.find(".featuresPITableRow").each(function() {
var tr = AJS.\$(this);
((tr.attr("team") == filter || filter == "0") && (tr.attr("iteration") == filter2 || filter2 == "All") && (tr.attr("status") == filter3 || filter3 == "All"))? tr.show() : tr.hide();
});
filter == "0" ? totalElem.text(oTotalValue) : totalElem.text(report.find("tr.featuresPITableRow:visible").length);
filter == "0" ? completedElem.text(oCompletedValue) : completedElem.text(report.find("tr.featuresPITableRow[category='Complete']:visible").length);
filter == "0" ? inProgressElem.text(oInProgressValue) : inProgressElem.text(report.find("tr.featuresPITableRow[category='In Progress']:visible").length);
filter == "0" ? notStartedElem.text(oNotStartedValue) : notStartedElem.text(report.find("tr.featuresPITableRow[category='New']:visible").length);
filter2 == "0" ? totalElem.text(oTotalValue) : totalElem.text(report.find("tr.featuresPITableRow:visible").length);
filter2 == "0" ? completedElem.text(oCompletedValue) : completedElem.text(report.find("tr.featuresPITableRow[category='Complete']:visible").length);
filter2 == "0" ? inProgressElem.text(oInProgressValue) : inProgressElem.text(report.find("tr.featuresPITableRow[category='In Progress']:visible").length);
filter2 == "0" ? notStartedElem.text(oNotStartedValue) : notStartedElem.text(report.find("tr.featuresPITableRow[category='New']:visible").length);
}
});
""")
}
ul(class:"property-list two-cols") {
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "Filter by Team:")
div(class:"value") {
form(class:"aui") {
select(id:"featuresPISelect", name:"Team") {
allTeams.each {k,v->
option(value:k, v)
}
}
}
}
}
}
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "Filter by Iteration:")
div(class:"value") {
form(class:"aui") {
select(id:"iterationSelect", name:"Iteration") {
piIterationVals.each {v->
option(value:v, v)
}
}
}
}
}
}
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "Filter by Status:")
div(class:"value") {
form(class:"aui") {
select(id:"statusSelect", name:"Status") {
allStatus.each {v->
option(value:v, v)
}
}
}
}
}
}
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "Total features:")
span(class:"value", id:"featuresPISearchCount", searchCount)
}
}
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "Completed features:")
span(class:"value", id:"featuresPICompletedCount", completedCount)
}
}
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "In progress features:")
span(class:"value", id:"featuresPIProgressCount", inProgressCount)
}
}
li(class:"item") {
div(class:"wrap") {
strong(class:"name", "Not started features:")
span(class:"value", id:"featuresPIToDoCount", toDoCount)
}
}
}
table(class:"aui aui-table-rowhover", id:"featuresPITable") {
thead {
tr(id:"featuresPITableHeader") {
th("Key")
th("Summary")
th(class:"featuresPITeamColumn", "Team")
th("Iteration")
th(title:"Estimated Feature Size","Size")
th("Feature added after PI Started")
th("Capability")
th("Status")
th(title:"Completed stories","Progress")
}
}
tbody {
issues.each { issue->
def stories = issueLinkManager.getOutwardLinks(issue.id).findAll { it.issueLinkType.name == epicLink }*.destinationObject
def totalStoriesCount = stories.size()
def doneStoriesCount = stories.count { it.status.statusCategory.name == "Complete" }
def donePercentage = totalStoriesCount? doneStoriesCount / totalStoriesCount * 100 : 0
def team = issue.getCustomFieldValue(teamCustomField) as Team
def teamID = team? team.id : "Empty"
def teamValue = team?.description?.title
def iterationValue = issue.getCustomFieldValue(iesIterationField)
def iterationAttr = iterationValue ? iterationValue : "Empty"
def status = issue.getStatus().name
def statusattr = status
def statusClass
def statusCategory = issue.status.statusCategory.name
def raduibuttonvalue =issue.getCustomFieldValue(radioButton) as String
def radioClass
def color = ""
if (raduibuttonvalue == "Yes"){
//color = "#FFAE42"
}
//writer.write("<script>var css = '#customfield_19870-val { color: white;background-color: ${color}; font-weight: bold; border-bottom: 2px solid ${color}; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style');head.appendChild(style);style.appendChild(document.createTextNode(css));</script>")
writer.write("<script>var css = '#customfield_19870-val { color: red; font-weight: bold; border-bottom: 2px solid red; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style');head.appendChild(style);style.appendChild(document.createTextNode(css));</script>")
if (statusCategory == "New") {
statusClass = "aui-lozenge aui-lozenge-subtle jira-issue-status-lozenge jira-issue-status-lozenge-blue-gray jira-issue-status-lozenge-max-width-medium"
}
else if (statusCategory == "In Progress") {
statusClass = "aui-lozenge aui-lozenge-subtle jira-issue-status-lozenge jira-issue-status-lozenge-yellow jira-issue-status-lozenge-max-width-medium"
}
else if (statusCategory == "Complete") {
statusClass = "aui-lozenge aui-lozenge-subtle jira-issue-status-lozenge jira-issue-status-lozenge-green jira-issue-status-lozenge-max-width-medium"
}
tr(team:teamID, iteration:iterationAttr,status:statusattr,class:"featuresPITableRow", category:statusCategory) {
td {
a(href:"/browse/$issue.key", issue.key)
}
td(issue.summary)
td(class:"featuresPITeamColumn", teamValue)
td(issue.getCustomFieldValue(iesIterationField))
td(issue.getCustomFieldValue(estFeatureSizeField))
td(issue.getCustomFieldValue(radioButton))
def capability = issue.getCustomFieldValue(parentLinkField)
td {
a(href:"/browse/$capability", capability)
}
td {
span(class:statusClass, issue.status.name)
}
td {
"aui-progressbar"(id:"epic-progress", title:donePercentage.intValue() + "%",value:donePercentage,max:100)
}
}
}
}
}
}
searchCount == 0 ? writer.write("<p>No features planned in PI</p>") : writer.write("$output")
return output