Javascript works in announcement banner but not when in web resource module.

Mizan Community Champion Nov 08, 2012

Hi All ,

I need to execute a javascript using web resource plugin module the same way it gets executed when i paste it in the announcement banner .

below is the xml

<web-resource key="my js" name="my js" >
        <resource type="download" name="test.js" location="/templates/test.js" />
		<context>jira.general</context>    
    </web-resource>

can someone please help me with this ??

The script does not get executed and is not even seen in the page source ... how can i make this script work ?

2 answers

1 accepted

This widget could not be displayed.

I think the problem is leading slash in location it should be templates/test.js

Mizan Community Champion Nov 08, 2012

Hi Vishwajeet,

Even after removing the slash the script does not get executed.

This widget could not be displayed.

Are you using WebresourceManager to make sure the resources are loaded?

$webResourceManager.requireResourcesForContext("com.jtricks.plugin-key:resource-module-key")

Mizan Community Champion Nov 08, 2012

I am not using any .vm files . I have a javascript which redirect to a link when i add a version in JIRA . Now i need to embed this script in a plugin instead of pasting it in the announcement banner .

Do i need to include a .vm file as resource?

My plugin key has a space eg: my plugin , can this be a reason ?

@Jobin : you don't need this in scenario he has mentioned, once he set the context to jira.general it should be available on all pages irrespective of required resource statement

@Mizan : I suspected the space but I thought that's just an example, I haven't scene any code with space in key, you can quickly try removing the same.

@Vishwa Ah, I see what you mean. Thought he is trying to get it in some plugin templates.

Mizan Community Champion Nov 08, 2012

@Vishwajeet: tried removing the space from the key but still script does not work.

Mizan Community Champion Nov 09, 2012

now i can see the script in the page source as below

<script type="text/javascript" src="/jira/s/en_US-tp7cj4/768/3/1.0-SNAPSHOT/_/download/resources/com.mizan.jscripts.jscripts:test/test.js" ></script>

the script is a simple alert however it is not working . its works when pasted in the anouncement banner .

Is there something else i need to specify in the script since Jira version is 5.1.8 ?

Mizan Community Champion Nov 09, 2012

The script works now , i was not removing the javascript tags from the js file . after remving it it works ...

Thank you Jobin and Vishwajeet for your support .

I will select Vishwajeets answer first becoz Jobin already has a lot of karma ;)

Mizan Community Champion Nov 11, 2012

Hi ,

The original script does not work only alert statement worked .

AJS.$(document).ready(function(){
          AJS.$('a').each(function(){
                if(AJS.$(this).html() =='Merge'){
AJS.$(document.body).on('submit', 'form', function(){
var pkey=document.getElementById("project-config-details-project-key").innerHTML;
var burl=AJS.$("input[title='baseURL']").val()
window.location.href=burl+"/browse/"+pkey+"#selectedTab=com.atlassian.jira.plugin.system.project%3Aversions-panel";
})
}
})
})

Is there something missing in the above script ?

did you checked pkey and burl getting expecting values ?

Note: if you modified existing js file and added new code? if yes, then you need to restart jira

Mizan Community Champion Nov 19, 2012

Yes i get expected values .. the script works when its in announcement banner but not when in web resource plugin.

Even after a restart the script did not work ..

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

88 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