Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

build script to create dashboard

Hi evryone,

I created a script in a RestEndpoints joined to a SciptFragment for create a button which will create a dashboard in your project when you click on it.

But since an update my script don't work and i don't know why because I use the current ScriptRunner doc.

The errors are at the line when I create the dashboard ( at 118  & 143 & 159 & 179 ).


The errors message:

Cannot find matching method com.atlassian.jira.portal.PortletConfigurationManager#addDashBoardItem( int, int, com.atlassian.gadgets.dashboard.Color, java.util;LinkedHashmap , com;atlassian;fugue.Option)


My Script:

import com.atlassian.jira.bc.JiraServiceContext
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.portal.PortalPage
import com.atlassian.jira.project.Project
import com.atlassian.jira.portal.PortletConfigurationManager
import com.atlassian.jira.bc.portal.PortalPageService
import com.atlassian.jira.sharing.SharedEntity
import groovy.transform.BaseScript
import org.apache.log4j.Level
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.gadgets.dashboard.Layout
import com.atlassian.gadgets.dashboard.Color
import com.atlassian.fugue.Option
import com.atlassian.query.Query
import com.atlassian.jira.jql.parser.DefaultJqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.type.ShareType

@BaseScript CustomEndpointDelegate delegate

EP_MTN(httpMethod: "GET") { MultivaluedMap queryParams, String body ->

// initialisation de la boite de dialogue
def dialog =
<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true"
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-amain">Passage de votre projet en projet de type Maintenance</h2>
<a class="aui-dialog2-header-close">
<span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
<div class="aui-dialog2-content">
Vous venez de rajouter un dashboard à votre projet,
ne pas ré-appuyer sur le bouton si vous ne voulez pas créer plusieurs dashboards dans votre projet.</strong><br />
Si vous avez cliqué par erreur sur ce bouton et que vous voulez <strong>effacer </strong>le dashboard créé,<br />
il vous suffit d'aller dans l'onglet <strong>Dashboards>Manage Dashboards>My</strong>,
et de le supprimer à l'aide du bouton d'option correspondant à votre Dashboard.
<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<button id="dialog-close-button" class="aui-button aui-button-link">Fermer</button>
<div class="aui-dialog2-footer-hint">Contacter <strong>Baptiste Muller</strong> en cas de <strong>problème</strong>
ou <strong>question.</strong></div>
// get the key of the current project
String pKey= queryParams.getFirst("projectKey")
log.debug "Project Id is ${pKey}"

// get the current project with his key
Project prj = ComponentAccessor.getProjectManager().getProjectObjByKey(pKey)

// initialisation of variables for creating the dashboard
def portletConfigurationManager = ComponentAccessor.getComponent(PortletConfigurationManager.class)
def portalPageService = ComponentAccessor.getComponent(PortalPageService.class)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
JiraServiceContext sourceUserServiceCtx = new JiraServiceContextImpl(user)

// get the name of the current project
def pName = prj.getName()
SearchRequestManager srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class)
String filter3Id = ""
List filters = srm.findByNameIgnoreCase(pName + " - Project filter")

// get the filter Id for the Two Dimensional Filter Statistics.1
if(filters != null && filters.size()>0 ) {
filter3Id = filters.get(0).getId()

// configuration of the dashboard(name & description)
def dashboardTemplate = new PortalPage.Builder()
.name(prj.getKey()+" - Dashboard")
def targetDash = portalPageService.createPortalPage(sourceUserServiceCtx, dashboardTemplate)

// initialisation of query for the filters
Query query1=
new DefaultJqlQueryParser().parseQuery("project =\""+prj.getName()+
"\" AND filter = \"COMMON - Current Year Maintenance Filter\" AND filter = \"COMMON - Estimated with no logs\"")
Query query2=
new DefaultJqlQueryParser().parseQuery("project =\""+prj.getName()+
"\" AND (filter = \"CPT - PA-Maintenance Filter\" OR issueFunction in subtasksOf(\"filter = 'CPT - PA-Maintenance Filter'\"))")

// initialisation of two filters for the dashboard
SearchRequest filter1=buildFilterWithName(prj, "Maintenance Montrol", query1)
SearchRequest filter2=buildFilterWithName(prj, "PA-Maintenance board filter", query2)

// get the filters Id
String filter1Id = filter1.getId()
String filter2Id = filter2.getId()

// création du dashboard en prenant comme modèle le dashboard de reference(CPT-Dashboard)

// first gadget
portletConfigurationManager.addDashBoardItem(, 0, 0,
"projectOrFilter": "",
"isConfigured": "true",
"gadgetTitle": "Maintenance (X Jrs (X*8 hrs) par FREQUENCE)",
"refresh": "false",
"sumSubTasks": "false",
"collapseFieldGroups": "true",
"filterid": "10707",
"groupByField": "issuetype",
"commentFirstWord": "",
"projectRole": "",
"num_weeks": "3",
"reporting_day": "",
"excludeGroup": "",
"user": "",
"projectid": prj.getId().toString(),
"group": "4sh-users"

// Filter Results
portletConfigurationManager.addDashBoardItem(, 0, 1,
"filterId": filter1Id,
"isConfigured": "true",
"columnNames": "issuetype|issuekey|summary|status|timespent|customfield_10208",
"isPopup": "false",
"num": "10",
"refresh": "false"

// Two Dimensional Filter Statistics.1
portletConfigurationManager.addDashBoardItem(, 1, 0,
"filterId": filter3Id,
"isConfigured": "true",
"sortDirection": "asc",
"isPopup": "false",
"ystattype": "statuses",
"more": "false",
"refresh": "false",
"sortBy": "natural",
"xstattype": "issuetype",
"numberToShow": "5"

// Two Dimensional Filter Statistics.1
portletConfigurationManager.addDashBoardItem(, 1, 1,
"filterId": filter2Id,
"isConfigured": "true",
"sortDirection": "asc",
"isPopup": "false",
"ystattype": "statuses",
"more": "false",
"refresh": "false",
"sortBy": "natural",
"xstattype": "issuetype",
"numberToShow": "5"
// création of the dialog box

// method to create a filter
SearchRequest buildFilterWithName(Project prj1, String name, Query query) {
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
JiraServiceContextImpl ctx = new JiraServiceContextImpl(user)
SearchRequestService searchService = ComponentAccessor.getComponent(SearchRequestService)

SearchRequest filter = new SearchRequest()
filter.setName(prj1.getName()+" - "+name)

// permission to share
def sharePerm = new SharePermissionImpl(null, ShareType.Name.PROJECT, prj1.getId().toString(), null)
filter.setPermissions(new SharedEntity.SharePermissions([sharePerm] as Set))

SearchRequest newfilter=searchService.createFilter(ctx,filter)

return newfilter;


0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

122 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you