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,366,726
Community Members
 
Community Events
168
Community Groups

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

Atlassian Community Events