Forums

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

Can't update field with behaviour on create screen

Elena Oleksenko
Contributor
June 22, 2018

Hello!
I need to update a default value for Description field when the option is selected in another field (Select List (cascading)), when creating issue. 

I created the behaviour and added the field that should be checked when changed, to this behaviour. 

But when I'm trying to create an issue and select the needed option in the Select List field, description field is not updated with the default value. 

Here is my script: 

import com.atlassian.jira.component.ComponentAccessor 
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.ModifiedValue

def targetField = getFieldByName("Description")
def defaultValue = """[TASKS|]""".replaceAll(/ /, '')
def cField = getFieldByName("Deployment flow")
def selectedOption = cField.getValue().toString()
if (selectedOption == "PHP"){
targetField.setFormValue(defaultValue)
}

 Please help to understand what I'm doing wrong and how to update description when the option is set in my custom field. 

Behaviours - Namecheap Tracker - Google Chrome 2018-06-22 13.08.12.png

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Daniel Yelamos [Adaptavist]
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 Champions.
May 30, 2018

Hi

Try this:

Add this import:

import groovy.json.JsonBuilder

 And this line before the comment that reads "API POST"

def finalJSON = new JsonBuilder(jsonBody).toString()).build()

That should output the JSON in the proper format.

Do say if I can help you further.

Cheers!
DYelamos

Andrew Downs
May 31, 2018

Thank you for the assist. Managed to get it working. Appreciate the help.

 

I ended up getting the concatenation working as base and it posts successfully. But will look at your code as well for a more robust method I think.

Daniel Yelamos [Adaptavist]
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 Champions.
May 31, 2018

Thanks:

Could you mark this answer as accepted so that other users know that this thread has been answered?

Do say if I can help you further.

Cheers
DYelamos

Vineela Durbha
Contributor
April 23, 2019

Hi @Andrew Downs 

I am trying to update a request using the your code

def body = [:]
body.put("IssueNumber","XCAP-688")
body.put("Priority","P4 (No Impact/Notify)")


def baseUrl = new URL("http://xxx/xxx/UpdatePriority");

HttpURLConnection connection = baseUrl.openConnection() as HttpURLConnection;
connection.requestMethod = "POST"
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body) }
connection.connect();

log.info ("URL=" +baseUrl +" Status= "+connection.getResponseCode() as String)

 

But it is throwing 500 error(whereas there is no issue with the api.Not sure why is it giving 500 error). If i am trying to pass json data as below I am getting 400 error

def body = """{"Priority": "P4 (No Impact/Notify)", "IssueNumber": "XCAP-688"}"""

 

Can you help me in passing json data

TAGS
AUG Leaders

Atlassian Community Events