Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I pass custom data with ajax Behaviours?

Emil Chapchakchi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 26, 2021

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
John Chin
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.
January 26, 2021

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.

Emil Chapchakchi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 28, 2021

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

John Chin
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.
April 8, 2021

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
AUG Leaders

Atlassian Community Events