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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

198 views 0 2
Read article

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