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

0 vote
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)

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,323 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot