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,293,546
Community Members
 
Community Events
165
Community Groups

Dynamically change set value of string custom field

Hello , 

I have 2 field .

1) Drop Down Field : With some values , A,B,C.

2) Simple Text Field (Single Line).

I have all 3 screens same for a issue type (view/create/edit).

Now I want whenever I create the ticket.

create.PNG

Based on drop down Value It must set/change the text field value dynamically . Not after Pressing the create button .

I have create script post function in create transition.

 post_function.PNG

 

Here is my code written .

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def country = customFieldManager.getCustomFieldObjectsByName('Bayer Lead Country')[0];
def currency = customFieldManager.getCustomFieldObjectsByName('Billing Currency')[0];

//def myTestField = customFieldManager.getCustomFieldObject(10024);

def countryvalue = issue.getCustomFieldValue(country)

log.warn(countryvalue)

if(countryvalue == "A") {
log.warn('if loop')
issue.setCustomFieldValue(currency,'EUR')
}
else if(countryvalue == "B") {
log.warn('china loop')
issue.setCustomFieldValue(currency,'CNY')
}
else{
log.warn('error')
issue.setCustomFieldValue(currency,'error')
}.

 

Please help me to acheive it dynamically over the create screen .

Also this code Always goes to else and set the value  as error after clicking on create button 

2 answers

1 accepted

Hi @Priti Sonar,

in my instance I have two fields: "Country" (select list) and "Currency" (text field). So, the behaviour code is the following:

import com.atlassian.jira.component.ComponentAccessor

def fldCurrency = getFieldByName("Currency")
String strCountry = ComponentAccessor.optionsManager.findByOptionId(getFieldByName("Country").formValue as Long)

switch (strCountry) {
case "China":
fldCurrency.setFormValue("CNY")
break
case "Europe":
fldCurrency.setFormValue("EUR")
break
case "United States":
fldCurrency.setFormValue("US")
break
default:
fldCurrency.setFormValue("")
}

 On Initialiser (optional) and on Field: Country.

Thank you so much , It is working as expected 

Hi @Priti Sonar ,

if this solution is ok for you, please could you accept my answer?

Thank you

Hi @Priti Sonar,

if you want set the field every time an item is selected from the drop-down menu, you must use a behavior and not a postfunction.
The postfunction is triggered only following a state transition (on creation from null to first workflow state).
Also, the code for the behavior is a bit different than that for a postfunction.

Hi @Andrea Pannitti ,

Thanks for this info .

Could you please let me know code snippet according to the requirement .

It will dynamically set the field correct ?

What change of code you are  talking about

Suggest an answer

Log in or Sign up to answer
TAGS

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