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

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

"Script to trigger REST API call " code in adaptivist library is throwing 404 error

Hi Team ,

This is the below scenario when i want to configure Scripted field .

Field Name -: Color Epic ​Field

Template -: Custom Template

Template-:

#if ($value > 5)

<h2> id=value1> $value </h2>

#else if( $value < 5)

<h2 id=value2> $value </h2>

#end

<style>
#value1

{ background-color: tomato;​color: white; }

#value2

{ background-color: green;​color: white; }

</style>

​I#if ($value > 5)

<h2> id=value1> $value </h2>

#else if( $value < 5)

<h2 id=value2> $value </h2>

#end

<style>
#value1

{ background-color: tomato;​color: white; }

#value2

{ background-color: green;​color: white; }

</style>

Script to find no of epic in issues

import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.issue.search.SearchService.ParseResult;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.issue.search.SearchException;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.*

String key = issue.getKey()
final String jqlquery = "issueFunction in issuesInEpics('issuekey= $key')"
log.warn(jqlquery)
def Searchmanager = ComponentAccessor.getComponentOfType(SearchService) //call searchservice component
def CurrentUser = (ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()) as ApplicationUser
def parsequery = Searchmanager.parseQuery(CurrentUser, jqlquery) // method which returns of type Searchservice.parseresult

int count;

if(parsequery.isValid()) // use method isvalid to check the query validation

{ count = (Searchmanager.searchCount(CurrentUser,parsequery.getQuery())).toInteger() }

log.warn("${count.getClass()}")
return count

above code is correct , I believe custom template code is also correct but not giving expected results

But returning output1 (please check attachment) instead it should return output2(please check attachment )

here unnecessarily if statement is added , please resolve this issue .

2 answers

1 accepted

0 votes
Answer accepted

When I tried your script, I found that you were missing an import for the SearchService... but also, I think this can be simplified with the @JiraAgileBean notation

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.pyxis.greenhopper.jira")
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
@JiraAgileBean
EpicLinkManager epicLinkManager


def issuesInEpic = epicLinkManager.getIssuesInEpic(issue)
return issuesInEpic.size()

Also, in my environment, this ran in about 10ms compared to 25-30ms for your code (using the same epic with 6 issues)

And finally, your velocity template seems overly complicated, isn't the following what you are trying to achieve?

<style>
.red-epic-count { background-color: tomato; color: white; }
.green-epic-count { background-color: green; color: white; }
</style>

#set( $Integer = 0 )
#set($epicCount = $Integer.valueOf($value))
#if($epicCount > 5)
#set($class="red-epic-count")
#else
#set($class="green-epic-count")
#end
<h2 class="$class"> $value </h2>

Yes same thing , Thank you very much

Your help is much appreciated.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

856 views 2 22
Read article

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