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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,539
Community Members
 
Community Events
184
Community Groups

Populate single select list using rest call data using script runner behaviors

Edited

i am trying to populate a single select custom field in create issue screen as per the dat ai get from a rest call. i'm using scriptrunner behaviors for it

my initialiser looks something like:

getFieldByName("fieldName").convertToMultiSelect([
ajaxOptions: [
url : "...",
query: true,
formatResponse: "general"
],
]) 

But here my field is not being populated by the api's response data.

can anyone tell me what am i missing.

1 answer

0 votes
Matthew Clark
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.
Feb 07, 2020

You need to create a rest endpoint that this behaviour code communicates with to get the options.

So start by making a rest endpoint that returns your data as we show here and then make the behaviour code talk to that endpoint via the rest endpoints URL as we show here.

 

Regards

Matthew

I'm having the same problem as the OP. I have created a REST endpoint and it returns my data just like your example shows. When I edit the field that the behavior is connected to and click in the search box. the icon spins for a second but I don't get any values. All I get is the "footer" text that I've defined in my endpoint response. 

At this point, I'm not actually looking at the characters typed into the search box in my endpoint code, I just return the whole list. That's the only thing I can think of that is different than the examples. Is there something I need to "do" with the query text? 

Thanks

Matthew Clark
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.
Oct 03, 2020

If you have set this up exactly as the guide pages say then the default behaviour is that it will only AUTO get repositories if you enter at least 4 characters into the text box.


See the following property


minQueryLength


in the behaviour code:


getFieldByName("TextFieldB").convertToMultiSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/githubRepoQuery",
query : true, // keep going back to the sever for each keystroke
minQueryLength: 4,
keyInputPeriod: 500,
formatResponse: "general",
]
])


If you do not enter at least the `minQueryLength` characters then you have to click the "down arrow" icon to force the field to request data from the endpoint.

If you have not set up the exact example in the guide then the problem may be with the return data that the rest endpoint is pulling from the external source. I suggest trying the URL for your rest endpoint locally in the browser URL bar to see if it returns what you expect

Regards
Matthew

Thanks for the reply Matthew,

I've tried setting the minQueryLength to various values with no change in behavior.

I've also checked my REST endpoint response in the browser and it looks like it matches the format of the example. Here's a snippet.

{

  • items: [
    • {
      • value: "xxx Investors",
      • html: "xxx Investors",
      • label: "xxx Investors"
      },
    • {
      • value: "American Stock Exchange",
      • html: "American Stock Exchange",
      • label: "American Stock Exchange"
      },
  • ],
  • total: 50,
  • footer: "footer"

}

(ugh, sorry. I'm not sure how to copy the jsonview output here and make it look normal but I'm pretty sure I have valid JSON)

I'm sure it's something simple but I don't know how to debug it further.

Thanks,

Tom

Well, I just found the "problem". I changed the text in my footer item from "footer" to (something longer?) "Select the Customer" and it started working. 

Dunno

Seems like either a bug or something that should be documented.

Thanks,

Tom

Matthew Clark
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.
Nov 18, 2020 • edited

Hi Tom

Apologies for the delay.

I had a go at using the word “footer” as the footer elements actual value and I can see what you mean.

If you alter just the footer of our GitHub example:


rt = [
//.... removed code for brevity
total : repos[“total_count”],
footer: “footer”
]

The Select list converted field will only ever show the word “footer” when you click the dropdown box with 1 or more characters entered.

If you have anything other than the word footer it works as expected.

It does appear to break the select list conversion field so it could be considered to be a bug.
This is likely an issue with how the behaviour method “.convertToMultiSelect” performs the conversion.
I will see if I can raise a bug for this so we have a record of the problem.

Thanks for finding this

 

Regards

Matthew

Like Tom Hudgins likes this

@Tom Hudgins 

Can you share the complete code and screenshots of the outcome for this? I want to use this approach for ServiceNow integration to Jira.

 

Appreciate your help on this.Thanks

Hi Rodolfo,

I can't really give you any better explanation on how to do this than what is already present in the documentation (linked in the first response above by Matthew Clark).

Newer docs are here: https://docs.adaptavist.com/sr4js/6.37.0/features/behaviours/behaviours-examples/select-list-conversions

I used that code almost exactly. The only thing that tripped me up was using "footer" in the footer text. Once I changed that, it worked.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events