Create new key while create project by API

HI All,

          How will get all project keys. Because while we create new project by API  i need to give different key. So before that i need to check all existing Key and create new Key. How will achieve this?

2 answers

1 vote
Vasiliy Zverev Community Champion Jan 14, 2016

Since you have a collection on project keys for each project you have to do a loop over all projects. Here is a code example how to get all project keys:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager

ProjectManager projectManager = ComponentAccessor.getProjectManager();

List<String> prjKeys = new ArrayList<>();

for(Project project: projectManager.getProjectObjects()){
    prjKeys.addAll(projectManager.getAllProjectKeys(project.getId()))
}

return prjKeys.toString()

can you please share your code.. I'm also working on something related to this

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

90 views 0 6
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