Forums

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

ScriptRunner Cloud. Getting fields for issue takes too long

Alexey Paveliev
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 Leaders.
January 30, 2021

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
Alexey Paveliev
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 Leaders.
January 31, 2021
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")
}
1 vote
Answer accepted
Kate Kabir
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 Leaders.
January 31, 2021

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

Alexey Paveliev
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 Leaders.
January 31, 2021

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!

Kate Kabir
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 Leaders.
January 31, 2021

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
Alexey Paveliev
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 Leaders.
January 31, 2021

This call apparently does not support this

Kristian Walker _Adaptavist_
Community Champion
January 31, 2021

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
Alexey Paveliev
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 Leaders.
January 31, 2021

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

Suggest an answer

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

Atlassian Community Events