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

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

This widget could not be displayed.

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

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

510 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you