web-resource contexts

how to include javascript on create and transition screens only ? because from javascript i am making rest call and loading javascrip as webresource and context as atl.general, due to this javascript will loading in all pages. so i want to restrict javascript load in specific screens.

javascript should be load on create, edit and transition screens only for this,

what contexts need to use??

6 answers

1 accepted

The following is working for me
var transition=$("#issue-workflow-transition-submit").val();
  var editScreen=document.getElementById('edit-issue-submit');
  var issueType = AJS.$("#type-val").text();
  var issueTypeValue=$.trim(issueType);	
  if((transition=='Update by CCB'||editScreen!=null) && issueTypeValue == 'Defect'){		

//code here ..
}

Tayyab Bashir Community Champion Mar 30, 2016

Hi @Rambanam Prasad, 
I have to add add some javascript to workflow transitions as well,

Where do I have to put this code in the plugin? in atlassian-plugin.xml?  

Using webresource module we can add javascript, check the following doc for more information 

https://developer.atlassian.com/confdev/confluence-plugin-guide/writing-confluence-plugins/including-javascript-and-css-resources

if above link does't help then let me know!

Tayyab Bashir Community Champion Apr 27, 2016

Hi, 
Using the above link I added javascript that runs on atl.general pages.
But I need the JS to run on transition screens,
You have given some solution:

var transition=$("#issue-workflow-transition-submit").val();
  var editScreen=document.getElementById('edit-issue-submit');
  var issueType = AJS.$("#type-val").text();
  var issueTypeValue=$.trim(issueType);
  if((transition=='Update by CCB'||editScreen!=null) && issueTypeValue == 'Defect'){       
 
//code here ..
}

 
Where am I supposed to add this and how? Could you please tell me I would appreciate that very much.

I want my JS to run on all the issue transition windows for the permissible groups and for all the issue types.  

1 vote
Mizan Community Champion May 07, 2012

You can let the context be atl.general and let your script decide when to execute

for example something similar to the below code :

if((AJS.$("#issue-create")||(AJS.$("#issue-edit")){

//your script

}

i am getting "Undefined" message,

i used following code

if(document.getElementById('edit-issue-submit') !=null || document.getElementById('issue-workflow-transition-submit') !=null || document.getElementById('create-issue-submit') !=null || document.getElementById('issue-create-submit') !=null){

//my JavaScript here
}

0 vote
Mizan Community Champion May 06, 2012

for create issue screen the context should be "jira.issue.create" This is available in 4.4 onwards

yes i seen this, but javascript should work on transition screens also :(

for you reference context for create screen is "jira.create.issue" not "jira.issue.create"(it won't work , tested on 5.0.3)

0 vote
Mizan Community Champion May 07, 2012

Does your js takes values from the document ? for example document.getElementById("pid") ?

bcoz pid is not available on transition screens . Even i had faced a similar problem, the js was not working on transition screen because i was trying to get pid

yes ur correct, but i am testing by giving just alerts

in transtion screens we can get issueid insted of pid

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Agile

What is ChatOps? A guide to its evolution, adoption, and significance

I am the product of AIM. I can hear that door swinging open and closed in my mind with absolute fidelity. I’d recognize that ding anywhere. At 15, as I typed away into AOL IM, I never imagined that ...

26 views 1 5
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