# AUI select2 - wrong appearance applying with Scriptrunner

**URL:** <https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630>\
**Category:** Confluence Server\
**Tags:** aui-select2, aui\
**Created:** [August 7, 2020, 6:48am UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630 "2020-08-07T06:48:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tw1](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/tw1/32/40520_2.png) [@tw1](https://community.developer.atlassian.com/u/tw1)\
**Post date:** [August 7, 2020, 6:48am UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630/1 "2020-08-07T06:48:05Z")

</div>

Hi colleagues,  
same issue as of this post of 2017; [AUI Select 2 not working properly](https://community.developer.atlassian.com/t/aui-select-2-not-working-properly/3542)  
Tried this code even but the result appears to be the same as the screenshot attached.  
Console provides an error like: AJS.MultiSelect is not a constructor…  
Presumably, there is something wrong of AUI settings on the server? Confuence v7.2.0, AJS.version 8.3.5.  
I tried the code of select2 AUI web page ([AUI Select2 - AUI Documentation](https://docs.atlassian.com/aui/8.3.5/docs/auiselect2.html)) prior to this post, but provided same result.  
 ![select2_wrong](https://global.discourse-cdn.com/atlassiandeveloper/original/3X/1/4/149ef1dd57f4b1d2925ce8bbb73f6423f4185d4c.png)

All aui class based forms do not work out for me.

Appreciate any support of what is going wrong.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/daz/32/35911_2.png) [@daz](https://community.developer.atlassian.com/u/daz)\
**Post date:** [August 7, 2020, 7:20am UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630/2 "2020-08-07T07:20:22Z")

</div>

Hi @tw1,

Are you building your own page in Confluence, or are you trying to extend an existing page?

How are you loading the front-end code for AUI? Are you requiring the web-resources for AUI’s forms and select 2 patterns?

Somewhere in your app’s Java code, you will need to make a call similar to the following (taken from [this Confluence docs page on web resources](https://developer.atlassian.com/server/confluence/web-resource-module/#referring-to-web-resources)):

```auto
@Named
public MyServlet extends HttpServlet {
    @ConfluenceImport
    private PageBuilderService pageBuilderService;

    @Inject
    public MyServlet(PageBuilderService pageBuilderService) {
        this.pageBuilderService = pageBuilderService;
    }

    // call this either in your page action or your web fragment renderer.
    // in either case, call it before your template is rendered.
    private void requireMyResources() {
        pageBuilderService.assembler().resources().requireWebResource("com.atlassian.auiplugin:aui-select2");
        pageBuilderService.assembler().resources().requireWebResource("com.atlassian.auiplugin:aui-forms");
    }
}

```

If you have your own JS and CSS to apply to your UI, instead of requiring the AUI resources directly from your Java code, you might instead create your own web-resource and require that instead:

In your `atlassian-plugin.xml` file:

```auto
<web-resource key="my-feature-resources">
  <dependency>com.atlassian.auiplugin:aui-select2</dependency>
  <dependency>com.atlassian.auiplugin:aui-forms</dependency>
</web-resource>

```

In your Java code, change the `requireMyResources` method to call this instead:

```auto
pageBuilderService.assembler().resources().requireWebResource("my.plugin.key:my-feature-resources");

```

Hope that helps!

---

<div class="post-metadata">

**Author:** ![tw1](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/tw1/32/40520_2.png) [@tw1](https://community.developer.atlassian.com/u/tw1)\
**Post date:** [August 7, 2020, 9:31am UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630/3 "2020-08-07T09:31:51Z")

</div>

Hi daz,  
thanks a lot for real fast reply.

Well, your question regarding loading… I forgot to mention. Via Adaptavist Scriptrunner for Confluence. Creating a scripted macro, which is going to load the J + JS code.  
I would rather refer to the atlassian-plugin.xml, which honestly does not exist yet on server. This is most probably my issue.  
Which way might be the better one, resources or xml file?  
Quite new, as I’ve been working w/ Jira before.

Thanks again for help.

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/daz/32/35911_2.png) [@daz](https://community.developer.atlassian.com/u/daz)\
**Post date:** [August 7, 2020, 9:50am UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630/4 "2020-08-07T09:50:24Z")

</div>

Ah, I’m not familiar with ScriptRunner’s capabilities for defining and loading UI code. Perhaps @jmort or @dluksza could chime in and offer assistance on that front?

---

<div class="post-metadata">

**Author:** ![dluksza](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/dluksza/32/35749_2.png) [@dluksza](https://community.developer.atlassian.com/u/dluksza)\
**Post date:** [August 7, 2020, 10:57am UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630/5 "2020-08-07T10:57:20Z")

</div>

Hi @tw1,

I’m one of the developers working on the ScriptRunner team.

In order to limit amount of data send to client and seed up page load times, the _Custom Macros_ doesn’t include any of the additional AUI dependencies. Select2 is one of those dependencies that are not available by default.

As @daz already mentioned you need require select2 on your own. In case of ScriptRunner _Script Macros_ you need to add:

```auto
import com.atlassian.webresource.api.assembler.PageBuilderService
import com.atlassian.sal.api.component.ComponentLocator

def pageBuilderService = ComponentLocator.getComponent(PageBuilderService)

pageBuilderService.assembler().resources().requireWebResource("com.atlassian.auiplugin:aui-select2");

```

to the **Macro code** configuration option. This code ensures that select2 will be loaded before client side code from _Custom Macro_ will be executed.

Hope this helps, let me know if you have any further questions.

---

<div class="post-metadata">

**Author:** ![tw1](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/tw1/32/40520_2.png) [@tw1](https://community.developer.atlassian.com/u/tw1)\
**Post date:** [August 7, 2020, 12:24pm UTC](https://community.developer.atlassian.com/t/aui-select2-wrong-appearance-applying-with-scriptrunner/40630/6 "2020-08-07T12:24:33Z")

</div>

Hi @dluksza,

thanks a lot.  
It perfectly works out now. Really, like posted in the initially mentioned link of mine, of AUI v8.3.5.

The question, did I miss any web post or is it professional developer knowledge?  
Thanks anyway to @daz and to you for really fast reply and resolution.  
Very much appreciate.

Since I am continuing to work w/ Scriptrunner I may have to address further inquiries directly…

Thanks again.
