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

How can I pass custom data with ajax Behaviours?

Edited

I have two custom fields: field1 and field2
Also I made sort of behavior for field1

getFieldByName("field1").convertToMultiSelect([
ajaxOptions: [
url: getBaseUrl()+"/rest/scriptrunner/latest/custom/doSomething",
query: true,
minQueryLength: 4,
keyInputPeriod: 500,
formatResponse: "general",
]
])



  How can I pass with this behavior any info about field2. I want something like this:

getFieldByName("test-field").convertToMultiSelect([
ajaxOptions: [
url: getBaseUrl()+"/rest/scriptrunner/latest/custom/doSomething",
query: true,
data: [
field_2_Value: value,
field_2_id: id
],
minQueryLength: 4,
keyInputPeriod: 500,
formatResponse: "general",
]
])



  And then, how can I catch this info in my endpoint doSomething?

1 answer

1 accepted

1 vote
Answer accepted

Hi Emil,

Welcome to the Atlassian Community.

I assume the first script is for field 1 and second script is for field 2. Then, you would like to get the field 1 value and pass into the field 2 script?

You can try pass the field1Value in the custom rest endpoint url:

def field1Value = getFieldByName("field1").getFormValue()

getFieldByName("test-field").convertToMultiSelect([
ajaxOptions: [
url: getBaseUrl()+"/rest/scriptrunner/latest/custom/doSomething?field1Value=${field1Value}",
query: true,
minQueryLength: 4,
keyInputPeriod: 500,
formatResponse: "general",
]
]) 

 In the custom rest endpoint, you can catch the field1Value value with this:

def field1Value = queryParams.getFirst("field1Value") as String

 I hope this helps. Do let me know if its working for you.

Yes, it did help! Thank you!
But here's a thing. The value of field1Value is null. It's probably because when I'm starting to create an Issue script starting to run and gets field1Value before I set it

Do you know is there any way to create a listener-function that would listen a field1, and pass its' value every time field1 changed

There is a way you can use Issue Updated event on the custom listener function and write a script to check the field1 when the field value was changed on the issue.

You can refer some source code here.

Suggest an answer

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

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

462 views 5 18
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