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

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 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

1 vote
Answer accepted
Vishwajeet Singh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2012

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

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2012

Hi Vishwajeet,

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

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2012

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

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

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 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 ?

Vishwajeet Singh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2012

@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.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2012

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

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2012

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

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 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 ?

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2012

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 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