Include external javascript file in velocity template

Hi All,

All I want to do is include an external javascript file how hard can that be you ask? well its turning into a nightmare, i have a web resource from an example plugin ive found:

com.atlassian.auiplugin:ajs requestedfields

and i want to include the java script file in a velocity template, so i can call a function:
function doSomething()
{
alert(‘hello world’)
}

thats it, thats all i want to do, I’ve seen people saying use something like this:

$webResourceManager.requireResource(“com.atlassian.auiplugin:requestedfields-resources”)

but i dont know what im supposed to pass to requireResource or where I’m meant to put this in my velocity template, can someone please help before I lose my mind and potentially go postal.

Thanks :slight_smile:

https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-resource-plugin-module (log question in two places, get answers in two places, eventually!)

but i dont know what im supposed to pass to requireResource

the web-resource bundle key.

or where I’m meant to put this in my velocity template

Probably doesn’t matter, style wise, we put it at the top.

I’ll throw you a bone. Here is a simplified example:

	<web-resource key="jemh-global" name="JEMH Javascript and CSS Resources">
		<resource type="download" name="jemhui.js" location="/templates/com/javahollic/jira/jemh/ui-js/jemhui.js" />
		<context>jemh.ui</context>
	</web-resource>

Here you can see the jemhui.js file, note the context. You could refer to the full resource key, but note the context, now, you can do this:

$webResourceManager.requireResourcesForContext("jemh.ui")

That will cause the resourcess in the context of jemh.ui to be loaded,ie, the script.