Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Select List Conversion filtering Edited

Hello dear@Thanos Batagiannis _Adaptavist_  , @Daniel Yelamos [Adaptavist], @Roland Holban _Adaptavist_

I've encountered problem with select list conversion.  Results in list highlighted but not filtered. 

As i can see screenshots in this instruction (which i followed), result should be filtered, but it is not.

filtered.png

Here is the code of rest endpoint:

import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import ru.raiffeisen.main.helpers.ConstantsHelper

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

getTemplates(httpMethod: "GET") { MultivaluedMap queryParams ->
def query = queryParams.getFirst("query") as String
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def rt = [:]
def jqlQuery = "project = \"TEST\" and status = In Progress"
def issueManager = ComponentAccessor.issueManager
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)

def query1 = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query1, user, PagerFilter.unlimitedFilter)
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("text custom field").first()
def templateList = results.issues.collect { issue-> issueManager.getIssueObject(issue.id).getCustomFieldValue(customField) }.findAll {it != null}
rt = [
items : templateList.collect { String row ->
[
value: row,
html: row.replaceAll(/(?i)$query/) { "<b>${it}</b>" },
label: row,
]
},
total: templateList.size(),
footer: "Choose template... "
]
return Response.ok(new JsonBuilder(rt).toString()).build();

 

And behaviour:

getFieldByName("Template").convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/getTemplates",
query : true, // keep going back to the sever for each keystroke
// this information is passed to the server with each keystroke
formatResponse: "general"
],
])

 

May be I am missing something common?

I ve tested it on Jira v7.2.15 and Scriptrunner versions: 5.2.2, 5.4.28

and Jira v7.8.1, SR v5.4.28

Thanks in advance!

 

4 answers

1 accepted

1 vote
Answer accepted

Hi Mark, 

You will need to do the filtering in your rest end point. 

So, for a case insensitive search, you will need something like 

def templateList = results.issues.collect { issue-> issueManager.getIssueObject(issue.id).getCustomFieldValue(customField) }.findAll {it != null} as List<String>

rt = [
items : templateList?.findAll { it.toLowerCase().contains(query?.toLowerCase())}?.collect { row ->

// rest of the script
}

That should do the trick, ping me if it doesn't :)

Kind regards, 

Thanos

Many thanks, @Thanos Batagiannis _Adaptavist_!

It works perfect!

As i noticed, for all time that i work with scriptrunner plugin, many useful things just not described in documentation, like this for example or for setFormValue have examples only for selectlists and textfields and for dates, userpickers, grouppickers need some R&D actions from users.

In my opinion behaviours very poorly documented, I am using Idea and see so many methods in behaviour api, which are not described. It will be great to do JavaDoc for them.

So i have one question.

Do Adapatavist have plans on improving documentation?

Hi Mark,

Glad that we made it work.

I hear you and you are right. The thing is that ScriptRunner abilities are endless and no kind of 'traditional' documentation can cover all the cases. 

So right now we are working into 2 major areas 

The first one is to improve our "traditional" documentation - in progress

The second one is a way to share scripts with the public in a better way than just examples in the documentation - in progress

Regarding the select list conversion issue itself, we are also working in a solution that will make it much more easier and more flexible. 

 

Kind regards and thanks a lot for the feedback,

Thanos

I have problem on setting default value on user picker on customer portal. I think I need this one. can you help? @Mark Markov

Hello @Mark Markov  and @Thanos Batagiannis _Adaptavist_ 

I need to implement something like this:

I want to create a select list field for a particular project with options which appear on screen as:

<value of a custom field(any other custom field) of an issue><space><Value of summary field of the same issue>

 and the no. of options should be same as the no. of issues in that particular project.

Could you please help.

Thanks and Regards,

Swapnil Srivastav.

@Thanos Batagiannis _Adaptavist_  , I have the same issue as @Mark Markov , but with diferent porpose as well as diferent code, isn't for a issue but for a request.  

Could you help me also? 

 

Regards 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

248 views 2 1
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