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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,739
Community Members
 
Community Events
176
Community Groups

Why does my script break re-indexing?

Hi team experts! This one took some time in finding the problem, and I know that you have the solution if I can just explain it well enough to understand.

The goal is to update a Scriptrunner scripted field using a common Custom Field between two Project Types.

Project A, Type 1 and Type 2 have a common field. The scripted field is on Type 1 and uses the common field to look up the value of a field that is only on Type 2. Confused?

In the script below, the Project is called PD4. Issue Type 1 isn't addressed because that is where the scripted field is. Issue Type 2 is called Control and the common Select List is called Family.

So for each record, the scripted field is using the value of Family to match the Control Issue Type that has the same value in Family. This is defined as query. Based on those results it takes the value of "Last Event Control" and defines it as last_event.

Somewhere in between the ////// marks is the part of the script that breaks re-indexing. I am not sure of all the options out there or if there is a better way to doing what we are trying to do. Any help would be appreciated. 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.event.type.EventDispatchOption;
import java.math.*
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.util.Map
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import org.codehaus.groovy.control.MultipleCompilationErrorsException
import com.atlassian.jira.issue.index.IssueIndexingService;

def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
def issueManager = ComponentAccessor.getIssueManager()
def CustomFieldManager=ComponentAccessor.getCustomFieldManager()

//Define the output of the scripted field
def late="Yes"

//Problem Rank
def String rank = issue.getCustomFieldValue(CustomFieldManager.getCustomFieldObjectsByName("Problem Rank")[0])

//Must Apply
def must_apply = issue.getCustomFieldValue(CustomFieldManager.getCustomFieldObjectsByName("Must Apply")[0])

///////////////////////////////////////////////////////////////////////
def searchService = ComponentAccessor.getComponent(SearchService)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)

def family = issue.getCustomFieldValue(CustomFieldManager.getCustomFieldObjectsByName("Family")[0]).toString()
def query = jqlQueryParser.parseQuery("project = PD4 AND issuetype = Control AND Family = ${family}")

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def results = searchService.search(loggedInUser, query, PagerFilter.getUnlimitedFilter())

def last_event = results.results[0].getCustomFieldValue(CustomFieldManager.getCustomFieldObjectsByName("Last Event Control")[0]).toString()
/////////////////////////////////////////////////////////////////////////

//Last Event turned into a number
int leint=0
//Must Apply turned into a number
int maint=0

if (must_apply=~"DAN0"){maint=1}
else if (must_apply=~"CERT"){maint=2}
else if (must_apply=~"DAN"){maint=3}
else if (must_apply=~"QC"){maint=4}
else if (must_apply=~"RC"){maint=5}
else if (must_apply=~"PP"){maint=6}
else if (must_apply=~"MP"){maint=7}
else {maint=0}

if (last_event=~"DAN0"){leint=1}
else if (last_event=~"CERT"){leint=2}
else if (last_event=~"DAN"){leint=3}
else if (last_event=~"QC"){leint=4}
else if (last_event=~"RC"){leint=5}
else if (last_event=~"PP"){leint=6}
else if (last_event=~"MP"){leint=7}
else {leint=-1}

// Is Must Apply earlier than Last Event
if (maint<=leint){return late}
// Is Must Apply later than Last Event
if (maint>leint){return null}

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Todd Palermo ,

I know that it's not recommended to perform JQL queries in scripted field because the JQL queries are unavailable during the lock re-index.

You should check if the index is available in your scripted field, check this documentation 

https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html#_jql_searches_in_script_fields

Hi @Italo Qualisoni [e-Core] 

Great job! You did it! Thanks so much for your help!

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events