Missed Team ’24? Catch up on announcements here.

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

Custom field to auto dispaly number of issues in an issue filter

Sanu Soman
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.
October 17, 2013

Hi All,

Please guide me is there any option is available to auto capture the number issues (just count) in a saved issue filter to a custom field as part of workflow post-function?

Thanks in advance.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
RambanamP
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.
October 20, 2013

you can try with following code but you need to add imports and little bit modifications

String jqlSearch = "filter= \"" + filterName + "\"";
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);
ParseResult parseResult = searchService.parseQuery(authenticationContext.getLoggedInUser(), jqlSearch);
int totalIssues = 0;
if (parseResult.isValid()) {
try {
SearchResults results = searchService.search(authenticationContext.getLoggedInUser(), parseResult.getQuery(), PagerFilter
						.getUnlimitedFilter());
final List<Issue> issues = results.getIssues();
totalIssues = issues.size(); 
//add code here to update custom field
} catch (SearchException e) {
e.printStackTrace();
}
}


Sanu Soman
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.
October 27, 2013

Hi Rambanam,

Thanks for sharing this.

I'm very much new to this programming. If possible could you please share how I can go ahead with this.

Sanu Soman
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.
October 28, 2013

Is this below code will work?

<script type="text/javascript">
String jqlSearch = "filter= \"" + demo + "\"";
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);
ParseResult parseResult = searchService.parseQuery(authenticationContext.getLoggedInUser(), jqlSearch);
int totalIssues = 0;
if (parseResult.isValid()) {
try {
SearchResults results = searchService.search(authenticationContext.getLoggedInUser(), parseResult.getQuery(), PagerFilter
.getUnlimitedFilter());
final List<Issue> issues = results.getIssues();
totalIssues = issues.size();
//add code here to update custom field
FormField category = getFieldById("customfield_10319")
category.setFormValue("totalIssues")
} catch (SearchException e) {
e.printStackTrace();
}
}
</script>

RambanamP
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.
October 28, 2013

hey! this is not javascript,

you have to try this code with script runner plugin, check this

https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions

or develop post function using javasyntax, check this to know how to develop postfunction

http://www.j-tricks.com/1/post/2010/08/workflow-post-function.html

Sanu Soman
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.
October 28, 2013

ah, is it a groovy script? could you please share me with this code how I can add a value (totalIssues) to a custom field?

0 votes
John Bishop
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.
October 20, 2013

Using the Script Runner plugin, you could write a post function script which would perform the following steps:

1. Use the JqlQueryBuilder to generate a query (The same query that's in your filter)

2. Use the SearchResults object to get the results of the query.

3. Get the count of the number of issues in the SearchResults list.

4. Store the number in a custom field.

0 votes
Sanu Soman
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.
October 20, 2013

Any suggestions guys?

TAGS
AUG Leaders

Atlassian Community Events