JIRA 7.X groovy error

I am trying to build a query:

Fetch all the fix versions of a ticket, see if that fix version is assigned to any other tickets in the same project.  Below script works fine for 6.X but it is throwing the below error in 7.X

Please help me to fix these errors.

Script69.groovy:61
[Static type checking] - Cannot find matching method com.atlassian.jira.ComponentManager#getSearchService(). Please check if the declared type is right and if the method exists.
@ line 61, column 47.
Script69.groovy:65
[Static type checking] - Cannot assign value of type com.atlassian.jira.user.ApplicationUser to variable of type com.atlassian.crowd.embedded.api.User
@ line 65, column 18.
Script69.groovy:66
[Static type checking] - Cannot find matching method com.atlassian.jira.bc.issue.search.SearchService#search(com.atlassian.crowd.embedded.api.User, com.atlassian.query.Query, com.atlassian.jira.web.bean.PagerFilter). Please check if the declared type is right and if the method exists.
Possible solutions: each(groovy.lang.Closure) @ line 66, column 16.

 

Issue curissue = issue
curissuekey = curissue.getKey();
Collection<Version> fixVersionList = issue.getFixVersions();
if (fixVersionList.size() > 0)
{
    for (Version v : fixVersionList)
    {
                fvname = v.getName();
                JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
                builder.where().project().eq("Project_name").and().fixVersion().in(""+fvname+"");
                Query query = builder.buildQuery();
                SearchService searchService = ComponentManager.getInstance().getSearchService();
                SearchResults results = null;
                try
                {
                                        User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
                                        results = searchService.search(user, query, PagerFilter.getUnlimitedFilter());
                }
                catch (Exception e){}
                nCount = results.getTotal();
    }
}

1 answer

1 accepted

It seems that your issue is related of using the ComponentManager as your SearchService and that's deprecated in favor of the ComponentAccessor class.

 

The problem is here:

SearchService searchService = ComponentManager.getInstance().getSearchService();

Try changing it to this instead:

SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);

 

 

Then there's another issue where you're trying to get the Current Logged in User and for that you'll need to import the ApplicationUser class as it changed as of Jira 7.x to use that instead of the atlassian.crowd class so simply add the following line on top of your code:

import com.atlassian.jira.user.ApplicationUser

Then change this code:

User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

To this one:

JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext()
ApplicationUser user = authContext.getLoggedInUser()

Hi Pinchus,

Thanks it worked like charm in JIRA 7.x.

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 May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

849 views 2 9
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