Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

New Adaptivist ScriptRunner searchProvider method for Jira 8?

Judah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
September 24, 2019

I am trying to refactor a Scriptrunner listener to work with the new Jira 8 updates. The listener should copy a custom field value from parent to all children on update. It was previously working w/ Jira 7.

Specifically, having trouble implementing searchProvider.search() method. Code block below...I have loads of new type check errors and don't know where to begin!!

jira8-priorityNumber.PNG

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.bc.issue.*
import static com.atlassian.jira.workflow.TransitionOptions.Builder;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.index.IssueIndexingService;
import com.atlassian.jira.issue.search.IssueSearchResultsFactory;
import com.atlassian.jira.issue.search.DocumentSearchResultsFactory;

def log = Logger.getLogger("com.acme.debug")
log.setLevel(Level.DEBUG)
Issue issue = event.issue

def key = issue.getKey()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager();
def field = customFieldManager.getCustomFieldObjects(event.issue).find { it.name == "Priority Number" }
def issueService = ComponentAccessor.getIssueService()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def parentLink = customFieldManager.getCustomFieldObjectsByName('Parent Link') // getting the Parent Link custom field
def customFieldValue = issue.getCustomFieldValue(parentLink) // Parent Link field value
def parentKey = (String) customFieldValue
def parentIssue = issueManager.getIssueObject(parentKey) // Parent issue object
def parentValue = issue.getCustomFieldValue(field)

def jqlSearch = "issuetype in (Feature,'Forecasting Placeholder',Epic,Story)and status not in (Done,'Feature Post-Implementation','Feature Released') and issuekey in childIssuesOf(" + key + ")";
def query = jqlQueryParser.parseQuery(jqlSearch)

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

results.getResults().each {documentIssue ->;

def childIssue = issueManager.getIssueObject(documentIssue.id)
def changeHolder = new DefaultIssueChangeHolder()
def childValue = childIssue.getCustomFieldValue(field)
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
field.updateValue(null, documentIssue, new ModifiedValue(childValue, parentValue), changeHolder)

issueIndexManager.reIndex(documentIssue)
}

 I have found my way here https://confluence.atlassian.com/jiracore/lucene-upgrade-975041047.html but I am so far, unable to translate these updates...

Any advice is appreciated! 

 

Logs: 

2019-09-24 12:36:25,462 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-09-24 12:36:25,462 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.search.providers.LuceneSearchProvider.search() is applicable for argument types: (com.atlassian.query.QueryImpl, com.atlassian.jira.user.DelegatingApplicationUser, com.atlassian.jira.web.bean.PagerFilter) values: [{issuetype in ("Feature", "Forecasting Placeholder", "Epic", "Story")} AND {status not in ("Done", "Feature Post-Implementation", "Feature Released")} AND {issuekey in childIssuesOf(ZSMBT-10)}, ...]
Possible solutions: search(com.atlassian.jira.issue.search.SearchQuery, com.atlassian.jira.web.bean.PagerFilter), search(com.atlassian.jira.issue.search.SearchQuery, com.atlassian.jira.web.bean.PagerFilter, java.util.Set), search(com.atlassian.jira.issue.search.SearchQuery, org.apache.lucene.search.Collector), each(groovy.lang.Closure)
	at Script402.run(Script402.groovy:49)

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Deleted user
November 20, 2018

Hi @Aurélie Geoffroy!

Use:

getUnderlyingIssue()

as your issue

Deleted user
November 20, 2018

If you want to use the values on the screen use getIssueContext()

Aurélie Geoffroy
November 21, 2018

Thank you I will try this morning.

I ll give you feed back soon  

Aurélie Geoffroy
November 21, 2018

WORK THANK YOU SO MUCH !!!!

// importation
import com.atlassian.jira.issue.Issue
def key2 = getUnderlyingIssue().getKey().toString()    // WORK :D

// formfield
def box2 = getFieldByName("test3")
box2.setFormValue(key2)

Aurélie Geoffroy
November 26, 2018

Simpson :)

Like Deleted user likes this
Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
June 17, 2022

@[deleted] sorry to ask, but im a beginner.

 

Can you explain what's the difference between 

log.debug('This issue underlying: ' + getUnderlyingIssue())

log.debug('This issue context: ' + getIssueContext())

 

Both seems to be returning same output. I'm confused

TAGS
AUG Leaders

Atlassian Community Events