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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Cloud. Getting fields for issue takes too long Edited

In a script listener I get few custom fields not available within the context using the following REST API

def cfReviewerNeededId = "customfield_12853"
def cfServiceTypeId = "customfield_12851"
def cfRequestTypeId = "customfield_12100"
def cfCategoryTypeId = "customfield_12847"

def result = get("/rest/api/2/issue/${issue.key}?fields")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200) {
logger.info("Success getting fields")
serviceType = result.body.fields[cfServiceTypeId]?.value
reviewerNeeded = result.body.fields[cfReviewerNeededId]?.value
requestType = result.body.fields[cfRequestTypeId]?.requestType.name
//that's a weird place to put the request type!
categoryType = result.body.fields[cfCategoryTypeId]?.value
} else {
logger.info("Error getting fields")
}

Recently it was taking up to over 10 seconds depending on the time of the day which is a concern.

Is there a faster way? Can I get few select fields and not the entire issue? Will this help? 

I could use an example of such to see if this works faster

Thannks!

2 answers

2 accepted

1 vote
Answer accepted

Hi  Alexey

Thank you for the question.

I can confirm that the "Search parsing timed out. You probably have a subquery that returns too many issues." error which you are receiving indicates that the sub-queries for the JQL functions returns too many issues.

Unfortunately, we can only execute queries for a maximum of 10 seconds before timing them out in order to avoid performance issues by having long-running searches.

In order to overcome this error, we would advise that you make your subquery more restrictive so that it returns fewer issues. in order to complete within the timeout period.

One way that you could look to restrict the subquery for the enhanced search function would be to look at limiting the query to only return inside a specific project or issues that were updated within a certain timeframe.

You can add a queryString paramater to your rest call to get the issue to just get the fields you require and we have an example of how this works https://scriptrunner-docs.connect.adaptavist.com/jiracloud/script-console.html#_bulk_update_multiple_issue_resolutions 

This example shows how to get just the resolution field but you can take this line and replace resolution with a comma-separated list of just the fields you want to return.

I hope this will help you.

Thank you, Kate

Thank you. But I am not interested in getting a list of issues based on a filter here.

Instead I need certain fields for ONE particular issue I am running a script listener for

Can you help with a REST API call that returns few listed fields (primarily custom ones with known Ids) optimized for time?

Thanks!

Hi Alexey

You can try to add the line below into his result rest call where you get the issues to just get the issue to only return the fields mentioned in your script.

.queryString("fields","customfield_12853,customfield_12851,customfield_12100,customfield_12847")

If you add this in then it will return just the fields you need and will make the API call faster.

I hope this will help you.

Thank you. 

Kate

Like Alexey Paveliev likes this

This call apparently does not support this

Hi Alexy,

I can confirm that what Kate has said is correct and that the Get Issue API which you are calling does support using the fields queryString Parameter and this is documented inside of Atlassian Documentation for this API here.

I have tested the code Kate has provided and can confirm if you include this in your API call that it will return just the fields that you have specified inside the issue object which is returned.

Regards,

Kristian

Like Alexey Paveliev likes this

I had to remove "?fields" from the URL and it worked!

def cfReviewerNeededId = "customfield_12853"
def cfServiceTypeId = "customfield_12851"
def cfRequestTypeId = "customfield_12100"
def cfCategoryTypeId = "customfield_12847"

//to summarize the answer below see comments
def result = get("/rest/api/2/issue/${issue.key}") //remove "?fields" !!!
//add .queryString parameter as follows
.queryString("fields", "customfield_12853,customfield_12851,customfield_12100,customfield_12847")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200) {
logger.info("Success getting fields")
serviceType = result.body.fields[cfServiceTypeId]?.value
reviewerNeeded = result.body.fields[cfReviewerNeededId]?.value
requestType = result.body.fields[cfRequestTypeId]?.requestType.name
categoryType = result.body.fields[cfCategoryTypeId]?.value
} else {
logger.info("Error getting fields")
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you