Convert Components field into single selection

Rodrigo Brandao February 13, 2017

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

0 votes
Binisha May 19, 2017

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.

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 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.

Binisha May 19, 2017
#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)

Suggest an answer

Log in or Sign up to answer