Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

creating map in loop, inconsistent behavior

Hello,

 

I have the following script which should create map of dashboards of all jira users with owner of this dashboard.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.portal.PortletConfigurationManager
import com.atlassian.jira.bc.portal.PortalPageService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService

PortalPageService portalPageService = ComponentAccessor.getComponent(PortalPageService)

UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class)

UserSearchParams userSearchParams = (new UserSearchParams   
.Builder())
.allowEmptyQuery(true)   
.includeActive(true)
 
.includeInactive(true)
 
.maxResults(20000).build()

def users = userSearchService.findUsers("", userSearchParams)
def dash = [:]
def dash2 =[:]

users.each{user ->   
def privdashboards = portalPageService.getOwnedPortalPages(user)

    privdashboards.each{dashboard ->
        dash.put(dashboard.getName(),user) 
        dash2.put(user,dashboard.getName())
               log.error "1111--${dash}" 
               log.error "2222--${dash2}"
 
}}

log.error "1111--${dash}"
log.error "22222--${dash2}"
return null

 

The problem is that dash collect what I expect so the list of all dashboards for all users but dash2 for each user only collect last dashboard so it overwrite value in smaller loop (privdashboards.each) and I don't get why. for me dash should be equal to dash 2 but it is not:

here is output from logs:

1111--[test111:admin(JIRAUSER10000)]
2222--[admin(JIRAUSER10000):test111]
1111--[test111:admin(JIRAUSER10000), test222:admin(JIRAUSER10000)]
2222--[admin(JIRAUSER10000):test222]
1111--[test111:admin(JIRAUSER10000), test222:admin(JIRAUSER10000), LStest111:lukasz(JIRAUSER10200)]
2222--[admin(JIRAUSER10000):test222, lukasz(JIRAUSER10200):LStest111]
1111--[test111:admin(JIRAUSER10000), test222:admin(JIRAUSER10000), LStest111:lukasz(JIRAUSER10200), LStest2222:lukasz(JIRAUSER10200)]
2222--[admin(JIRAUSER10000):test222, lukasz(JIRAUSER10200):LStest2222]
1111--[test111:admin(JIRAUSER10000), test222:admin(JIRAUSER10000), LStest111:lukasz(JIRAUSER10200), LStest2222:lukasz(JIRAUSER10200)]
22222--[admin(JIRAUSER10000):test222, lukasz(JIRAUSER10200):LStest2222]

1 answer

1 accepted

0 votes
Answer accepted
tom lister Community Leader Jan 29, 2021

Hi @Łukasz Sielski 

The map has a unique key. Dash2 is using user as a key. So you only see one entry for the user.

hmm 

so this mean that if I use put on map it create new entry just in case key doesn't exist but if it already exist it change that key...

In such case, if I have 2 dashboards with the same name it will overwrite user in "dash" case.

So I need to refer to dashboard ID which is unique value...

Anyway, thank you I was understanding map as a list where you put value after value and they can be duplicated now i understand what is the case.

Best,

Lukasz

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,104 views 8 28
Join discussion

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