Behaviours Plug-in - Setting default value on custom field?

Robert Adler December 29, 2015

We added 2 behaviours scripts to pre-populate a custom field (single select list) with a default value. The first script works, however, the second one listed does not work (using different custom field, different value). Can someone please help?

 

THIS ONE IS WORKING:

// set a select list value -- also same for radio buttons

def PCRT = getFieldByName("Price Change Request Type")

def PCRToptionsManager = ComponentAccessor.getOptionsManager()

def PCRTcustomFieldManager = ComponentAccessor.getCustomFieldManager()

def customField = PCRTcustomFieldManager.getCustomFieldObject(PCRT.getFieldId())

def PCRTconfig = customField.getRelevantConfig(getIssueContext())

def PCRToptions = PCRToptionsManager.getOptions(PCRTconfig)

def PCRToptionToSelect = PCRToptions.find { it.value == "Promotion and Reversal" }

PCRT.setFormValue(PCRToptionToSelect.optionId)

 

THIS ONE IS NOT WORKING:

// set a select list value

def RT = getFieldByName("Request Type")

def RToptionsManager = ComponentAccessor.getOptionsManager()

def RTcustomFieldManager = ComponentAccessor.getCustomFieldManager()

def customField = RTcustomFieldManager.getCustomFieldObject(RT.getFieldId())

def RTconfig = customField.getRelevantConfig(getIssueContext())

def RToptions = RToptionsManager.getOptions(RTconfig)

def RToptionToSelect = RToptions.find { it.value == "Landing Page Creation" }

RT.setFormValue(RToptionToSelect.optionId)

 

We tried switching out the second script with the custom field ID to see if that helps, but still does not work. Does anyone have any suggestions?

 

Oddly, we discovered that when mapping to another issue type/project it works. However, when both are mapped to the same project/issue type only the first script works.

 

Thanks!

2 answers

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2016

Hi Robert,

Could you please provide some screenshots of here of how you have configured your behaviours as well as what version of JIRA and Script Runner you are using.

 

I have taken your code above and tested it in two select list fields which I created using the configuration shown in the screenshot below.

 

config.png

This worked correctly for me and shows the default values when I open the create issue screen as shown in the screenshot below.

image2016-1-21 16:50:36.png

I configured these behaviours using JIRA 6.4.12 and Script Runner 4.1.3.4.

I hope this helps

Thanks

Kristian

0 votes
Robert Adler January 21, 2016

Hi Kristian,

Thanks very much for your response! We were able to workaround this issue by just using the JIRA contexts in the custom field configurations to set different defaults per project/issue type.

Really appreciate you trying to reproduce this though. I did notice a major difference in your screenshot, versus what I had in my behaviours config. Instead of Field: Request Type, I noticed mine has Initialiser Function. We also had 2 separate behaviours scripts for each. I wonder if one of these 2 differences was the reason we couldn't get it to work.

 

Screen Shot 01-21-16 at 01.42 PM.PNG

 

FYI - we're running JIRA 6.3.13 and ScriptRunner 3.1.4

 

Thanks again,

Robert

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events