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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Add an existing Issue type to a existing issue type scheme using groovy

Hi,

I am trying to add an existing Issue type to a existing issue type schemes in specific projects.

I am trying o use scriptrunner for that, I can access the  Issue type and the Issue type scheme.

But I haven't found any method to add this issue type to the project issue type scheme.

I will appreciate any help .

 

Many thanks

1 answer

1 vote
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 04, 2021

Hi @Jose Suanzes welcome on the community. I think you can use IssueTypeSchemeManager component (https://docs.atlassian.com/software/jira/docs/api/8.0.0/com/atlassian/jira/issue/fields/config/manager/IssueTypeSchemeManager.html).

There are following methods which might be interesting for you

  • getConfigScheme - to get issuetypescheme for your project
  • OR
  • getAllSchemes - to get all the schemes
  • getIssueTypesForScheme - to get issuetypes for the scheme
  • update - to update scheme with adjusted collection of issuetype IDs

SO it might be

  1. search for required scheme based on the Project or filter it by name (or anything else)
  2. get Collection<String> of issueTypeIds
  3. update collection with required issueTypeId
  4. update issue type scheme with updated collection

Hi @Martin Bayer _MoroSystems_ s_r_o__ 

 

When I am calling to update I am getting the following error:

 

groovy.lang.MissingMethodException: No signature of method: Script35.update() is applicable for argument types: (com.atlassian.jira.issue.fields.config.FieldConfigSchemeImpl, ArrayList) values: [com.atlassian.jira.issue.fields.config.FieldConfigSchemeImpl@2083baf3, ...]
Possible solutions: putAt(java.lang.String, java.lang.Object)
at com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate.methodMissing(CustomEndpointDelegate.groovy:28)
at Script35.run(Script35.groovy:112)

 

Any idea what can be wrong?

 

Many thanks

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Mar 24, 2021

Hi @Jose Suanzes can you share the script?

something like this:

 

def KEY_NEW_PROJECT = "YEYG"
Project project = ComponentAccessor.getProjectManager()getProjectObjByKey(KEY_NEW_PROJECT);

IssueTypeSchemeManager its = ComponentAccessor.getIssueTypeSchemeManager();

FieldConfigScheme p = its.getConfigScheme(project);


Collection<IssueType> Itsm = ComponentAccessor.getIssueTypeSchemeManager().getIssueTypesForProject(project);

 


Collection<String> collection =   Itsm.eachWithIndex { val, idx -> println "$val in position $idx" }.id ;   

collection.add(11800)


update(p,collection);

 

 

regards

Hi @Jose Suanzes , We had the same requirement. Try this it worked for us.

try by running the below snippet.

I made 2 changes, id 11800 must be string and update method needs to be invoked on its (object of IssueTypeSchemeManager )

 

def KEY_NEW_PROJECT = "YEYG"
Project project = ComponentAccessor.getProjectManager()getProjectObjByKey(KEY_NEW_PROJECT);

IssueTypeSchemeManager its = ComponentAccessor.getIssueTypeSchemeManager();

FieldConfigScheme p = its.getConfigScheme(project);


Collection<IssueType> Itsm = ComponentAccessor.getIssueTypeSchemeManager().getIssueTypesForProject(project);

 


Collection<String> collection =   Itsm.eachWithIndex { val, idx -> println "$val in position $idx" }.id ;   

collection.add(11800)

collection.add('11800')

update(p,collection);

its.update(p,collection); 

Hi @Kesaboina BMV Sai Krishna ,

    The above mentioned script runs if only 1 project is specified in the "def KEY_NEW_PROJECT" section.Instead of running it for a single project at a time is there a way to run it on multiple projects and execute the scrpit in a single go,Can you guide me in this problem.

 

 

Thanks & Regards,

Ganesh

Hi @Ganesh Choubey D general groovy case is to create list 

List projects =['ke1', 'key2'....]

and iterate through it. For example
projects.each{KEY_NEW_PROJECT ->

// code above here

or real Jira case is to iterate through projects category(ies)

def List categories = ["Category1","Category2"]
categories.each{ category ->
    def categoryId = ComponentAccessor.getProjectManager().getProjectCategoryObjectByNameIgnoreCase(category).getId()
     //iterate over all projects in category
   ComponentAccessor.getProjectManager().getProjectObjectsFromProjectCategory(categoryId).each{ project->
   
        // your code here and take into account that project is already an object
       //  so next line is not required
//Project project=ComponentAccessor.getProjectManager()getProjectObjByKey(KEY_NEW_PROJECT);
    }
}
Like Ganesh Choubey D likes this

Suggest an answer

Log in or Sign up to answer