Groovy script for setting a value in a mandatory select list custom field during issue creation fails

Could anyone help me out with the issue below?

I have a groovy script which requires a select list custom field to create a new issue. The problem I do have is that if the custom field is made optional, the new issue is created but when it is made mandatory/required, the new issue is not created. As it is both important that the custom field is mandatory and new issues can be created programmatically, I am not able to make any further progress.

This is a snippet of the code which sets the value of the select list custom field called 'Story Type'

// The Story Type to be used for the new issue

   CustomField StoryTypeCF = customFieldManager.getCustomFieldObjectByName("Story Type")

   fieldConfig = StoryTypeCF.getRelevantConfig(issue)

   option = optionsManager.getOptions(fieldConfig).find {it.value == "Delivery"}            

   newIssue.setCustomFieldValue(StoryTypeCF, option)

 

While I investigate further, any help will be appreciated.

6 answers

0 vote

> I have a groovy script which requires a select list custom field to create a new issue What is the context for this... validator, behaviour, something else? Can you confirm which plugin you're using to execute the code. ta.

Hi Jamie, Thanks for getting back to me. The custom field has been set as ‘required’ in the field configuration so a user has to select an option from that field to be able to create an issue. This also applies to my script which only creates an issue when the field is made optional but fails when it is set as required in the field configuration or as a validator in the ‘Create’ transition. We are currently using the ScriptRunner Plugin v3.1.3

Any suggestions on why this is happening?

Hi Chris,

Have you considered using a Post Function to update the value of the Story Type field. Validators are designed to check the input of a field on a transition is valid rather than update the value of a field.

Kristian

Hi Kristian,

Thanks for the feedback.

The background to my problem is that I have a groovy script which automatically creates a new story during the creation of an Epic and as part of that process, the 'Story Type' field is required. In our field configuration setup, it is always made 'Required' so that users do not forgot to enter a value during manual creation as shown in the screenshot below

 

image2015-10-27 10:4:44.png

My problem is that when this 'Story Type' custom field is 'Required', the new story issue type is not automatically created but when it is changed to be 'Optional'(this is not our default setup) as shown in the screenshot below, then it is then created. My question is why this is happening?

image2015-10-27 10:7:56.png

If additional information is required, please do let me know.

0 vote

How does it fail... have you got a stack trace?

Hi Chris,

 

Could you please attach a code the code for this groovy script to this ticket along with some screenshots of where and how you have configured the script to run so that we can look to replicate this issue and look to find a solution.

 

Also could you please tell us what version of JIRA you are running this code in.

 

Many Thanks

 

Kristian

 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

216 views 1 18
Join discussion

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