# "Undefined" when trying to use Soy template?

**URL:** <https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922>\
**Category:** Jira Server\
**Tags:** javascript, soy, jira-server\
**Created:** [July 4, 2017, 5:36pm UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922 "2017-07-04T17:36:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![schollemarcus](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@schollemarcus](https://community.developer.atlassian.com/u/schollemarcus)\
**Post date:** [July 4, 2017, 5:36pm UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/1 "2017-07-04T17:36:58Z")

</div>

Hey together,

so I’m having some issues implementing my Soy template into my plugin.  
The following is present:

plugin.xml

```auto
    <web-resource key="library-management-resource-module" name="Wfenhance Library Management resource module">
        <dependency>com.atlassian.auiplugin:ajs</dependency>
        <dependency>com.atlassian.auiplugin:aui-select2</dependency>
        <dependency>com.atlassian.auiplugin:aui-experimental-soy-templates</dependency>
        <transformation extension="soy">
            <transformer key="soyTransformer">
                <functions>com.atlassian.confluence.plugins.soy:soy-core-functions</functions>
            </transformer>
        </transformation>
        <resource type="download" name="responsible-user-search.js" location="/js/responsible-user-search.js"/>
        <resource type="download" name="respusersearch-soy.js" location="/templates/respusersearch.soy"/>
        <context>jira-wfenhance</context>
    </web-resource>

```

respusersearch.soy

```auto
{namespace JIRA.Templates.wfenhance}

{template .userSearch}
<form class="aui" id="kdp-user-select-form">

    <div class="field-group">
        <label for="kdp-user-select">Users</label>
        <div id="kdp-user-select"
                 name="kdp-user-select"
                 class="kdp-aui-select"
                 multiple=""
                 placeholder="start typing a username ...">
        </div>
        <div class="description">The users that should have kitchen duty.</div>
    </div>
    <div class="buttons-container">
        <div class="buttons">
            <input class="button submit" type="submit"
                   id="kdp-user-select-save-button"
                   value="show"/>
        </div>
    </div>

</form>
{/template}

```

success.vm (view where the template should appear)

```auto
<html>
<head>
    <title>$i18n.getText("wfenhance.library-management.title")</title>
    <meta name="decorator" content="atl.admin">
</head>
<body>`Preformatted text`
<h1>$i18n.getText("wfenhance.library-management.headline")</h1>

<div id="kdp-user-select-form"></div>

<p>Here you can manage your present library definitions and import or export them.</p>
</body>
</html>

```

The js file (responsible-user-search.js)

```auto
/**
 * Created by schol on 7/4/2017.
 */
var initUserSearch = function() {

   /* The following line is fine, I can see it has objects. However, my own is missing. */
    var test1 = JIRA.Templates;

    /* Consequently, the following line returns the described error */
    var templateUserSearch = JIRA.Templates.wfenhance.userSearch();

};

AJS.toInit(function(){
    require(['aui/flag'], function(flag) {
        var myFlag = flag({
            type: 'success',
            title: 'JIRA Wfenhance Responsible user search',
            body: 'JIRA Wfenhance Responsible user search controller is working'
        });
    });

    initUserSearch()
})

```

Someone has an idea where something could be wrong?  
I can see that the template doesn’t get found in the Dev Console.  
I noticed my namespace seemingly can’t be found.  
I don’t think it’s related to my resource as other code from the JavaScript file works (the flag shows up).

Greetings Marcus

---

<div class="post-metadata">

**Author:** ![pvandevoorde](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/pvandevoorde/32/37172_2.png) [@pvandevoorde](https://community.developer.atlassian.com/u/pvandevoorde)\
**Post date:** [July 4, 2017, 6:09pm UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/2 "2017-07-04T18:09:10Z")

</div>

Hi Marcus,

Maybe something stupid but can you try removing the leading / in your location path?  
Like in the example: [https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-resource-plugin-module](https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-resource-plugin-module)

---

<div class="post-metadata">

**Author:** ![schollemarcus](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@schollemarcus](https://community.developer.atlassian.com/u/schollemarcus)\
**Post date:** [July 4, 2017, 6:53pm UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/3 "2017-07-04T18:53:27Z")

</div>

Unfortunately no, that doesn’t help.  
Something I noted tough:  
When looking at the script in the dev console something like this should be given at the start:

```auto
;/* module-key = 'com.comsysto.kitchen-duty-plugin:kitchen-duty-plugin-resources--planning-page', location = 'templates-soy/kitchen-duty-planning.soy' */
// This file was automatically generated from kitchen-duty-planning.soy.
// Please don't edit this file by hand.

/**
 * @fileoverview Templates in namespace JIRA.Templates.KDP.
 */

```

The example above is from a working version according to that tutorial here: [Redirecting ...](https://comsysto.github.io/kitchen-duty-plugin-for-atlassian-jira/tutorial/06-step-03-planning-page--user-search-js-controller/)

However, the view I’m having just starts like this:

```auto
;/* module-key = 'com.scholledev.jira-wfenhance:library-management-resource-module', location = 'js/responsible-user-search.js' */
var showSuccessFlag = function(a) {
    require(["aui/flag"], function(c) {
        var b = c({

```

---

<div class="post-metadata">

**Author:** ![ianRagudo](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/ianragudo/32/44527_2.png) [@ianRagudo](https://community.developer.atlassian.com/u/ianRagudo)\
**Post date:** [July 5, 2017, 1:51am UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/4 "2017-07-05T01:51:37Z")

</div>

Hi @schollemarcus,

It seems you’re missing SoyDoc in your template. I tested it out using your .soy file and was able to hit an error, although I didn’t get “Undefined”. Kindly add SoyDoc like

```auto
/**
* This is user search and a sample SoyDoc
**/
{template .userSearch}

```

Once I added this in the soy template you provided, it works already.

---

<div class="post-metadata">

**Author:** ![schollemarcus](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@schollemarcus](https://community.developer.atlassian.com/u/schollemarcus)\
**Post date:** [July 5, 2017, 3:37am UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/5 "2017-07-05T03:37:30Z")

</div>

Thanks for your comment and actually you’re right. I was able to sort this out. However there’s one more thing to mention - that got me undefined errors in the end: **No blank spaces at the start of the Javadoc lines.**

Greetings Marcus

---

<div class="post-metadata">

**Author:** ![rafael.moreira](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/rafael.moreira/32/37566_2.png) [@rafael.moreira](https://community.developer.atlassian.com/u/rafael.moreira)\
**Post date:** [April 4, 2019, 12:28pm UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/6 "2019-04-04T12:28:26Z")

</div>

Hi @ianRagudo,

Thank you so much, man!  
It works for me as well, saved my life!

My question is, Why does that soy templates needs “Soy-docs” to work?

Thank you again anyway!

🙂

---

<div class="post-metadata">

**Author:** ![ianRagudo](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/ianragudo/32/44527_2.png) [@ianRagudo](https://community.developer.atlassian.com/u/ianRagudo)\
**Post date:** [April 4, 2019, 10:39pm UTC](https://community.developer.atlassian.com/t/undefined-when-trying-to-use-soy-template/5922/7 "2019-04-04T22:39:53Z")

</div>

You’re welcome, @rafael.moreira. Soy templates or Google Closure templates requires a preceding Javadoc looking SoyDoc comments prior to a template. As to exactly why, I’m not 100% sure where it is being used under the hood, but it’s required as documented AFAIK.

Cheers,  
Ian
