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.
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.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.