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!
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")
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This call apparently does not support this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had to remove "?fields" from the URL and it worked!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.