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

0 votes
Answer 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 ..
}

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!

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.  

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
}

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)

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
Community showcase
Posted 4 hours ago in United States

Atlassian acquires AgileCraft

         Good Day, Bad bad traffic, not sure why!!!! 1/2 hour commute took me 2 hours today 🤯 What helped me is that I kept browsing LinkedIn until...

25 views 1 0
View post

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