Convert Components field into single selection

I need to prevent users from selecting more than one component when creating new tickets, so I'll be able to work with auto-assignement by component according component selection. 

Currently JIRA allows multi-selection for components and assigns the ticket to component lead of the last component selected on the ticket creation.

I already tested the JIRA Misc Workflow Extensions plugin and it works, however we've already purchased the Scriptrunner plugin. 

I know it's possible to add a Behavior using Scriptrunner, however all examples I found here at answers are not working. 

I'm working with JIRA 7.x and Scriptrunner 4.3.16.

Thanks,

2 answers

This widget could not be displayed.
Tarun Sapra Community Champion Feb 14, 2017

In the create transition, you can put a custom script in the "validation" phase of the transition. Script runner provides ability to write "Custom script validator" in the  validation phase and in the validation phase you can check how man components the issue has, and if it has more than 1 component you can return false.

#disable_html_escaping()
#customControlHeader ($action $field.id $i18n.getText($field.nameKey) $fieldLayoutItem.required $displayParameters $auiparams)
#if ($components && !$components.empty)   
    #if (!$fieldLayoutItem.required)
        #set ( $componentHeaderSize = 1)
    #end
    <select class="select" id="$field.id" name="$field.id"
            size="#minSelectSize($components $componentHeaderSize 5)"
            data-remove-null-options="true" data-submit-input-val="true" data-input-text="#if (!$bulkEdit)$textutils.htmlEncode($!frotherInputText)#end" data-create-permission="$!{createPermission}">
        #if (!$fieldLayoutItem.required)
            <option#if ($currentComponents && $unknownComponentId && $currentComponents.contains($unknownComponentId)) selected="selected"#end value="-1">
                $i18n.getText('common.words.unknown')
            </option>
        #end
        #foreach ($component in $components)
            <option#if ($currentComponents && $component && $currentComponents.contains($component.id)) selected="selected"#end title="$textutils.htmlEncode($component.name) #if($component.description) - $textutils.htmlEncode($component.description)#end" value="$!component.id">
                $textutils.htmlEncode($component.name)
            </option>
        #end
    </select>
    #if ($!isFrotherControl)<div class="description">${i18n.getText('generic.picker.static.desc')}</div>#end
#else
    <span class="field-value">$i18n.getText('common.words.none')</span>
#end
#customControlFooter ($action $field.id $fieldLayoutItem.getFieldDescription() $displayParameters $auiparams)
This widget could not be displayed.

Take a backup of components-edit.vm and then add the following

#disable_html_escaping()
#customControlHeader ($action $field.id $i18n.getText($field.nameKey) $fieldLayoutItem.required $displayParameters $auiparams)
#if ($components && !$components.empty)  
    #if (!$fieldLayoutItem.required)
        #set ( $componentHeaderSize = 1)
    #end
    <select class="select" id="$field.id" name="$field.id"
            size="#minSelectSize($components $componentHeaderSize 5)"
            data-remove-null-options="true" data-submit-input-val="true" data-input-text="#if (!$bulkEdit)$textutils.htmlEncode($!frotherInputText)#end" data-create-permission="$!{createPermission}">
        #if (!$fieldLayoutItem.required)
            <option#if ($currentComponents && $unknownComponentId && $currentComponents.contains($unknownComponentId)) selected="selected"#end value="-1">
                $i18n.getText('common.words.unknown')
            </option>
        #end
        #foreach ($component in $components)
            <option#if ($currentComponents && $component && $currentComponents.contains($component.id)) selected="selected"#end title="$textutils.htmlEncode($component.name) #if($component.description) - $textutils.htmlEncode($component.description)#end" value="$!component.id">
                $textutils.htmlEncode($component.name)
            </option>
        #end
    </select>
    #if ($!isFrotherControl)<div class="description">${i18n.getText('generic.picker.static.desc')}</div>#end
#else
    <span class="field-value">$i18n.getText('common.words.none')</span>
#end
#customControlFooter ($action $field.id $fieldLayoutItem.getFieldDescription() $displayParameters $auiparams)

 

And restart your server and check.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

178 views 1 3
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