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

C Abone September 13, 2015

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 votes
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.
December 30, 2015

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

 

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2015

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

0 votes
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.
October 23, 2015

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

C Abone October 27, 2015

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 votes
C Abone September 17, 2015

Any suggestions on why this is happening?

0 votes
C Abone September 14, 2015

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

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 14, 2015

> 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.

Suggest an answer

Log in or Sign up to answer