Hello Team,
I have an AJAX code with me, which I would like to place near the description of a custom field and make sure auto populating of field values onto the create screen happens, but it does not work. Here is my code.
<script type="text/javascript">
(function($) {
function prepopulateTeam(){
//$(document.getElementById("issuetype-field")).change(function(){
$(document.getElementById("customfield_14041")).change(function(){
issueType = document.getElementById("issuetype-field").value;
//system=document.getElementById("customfield_14041").value;
//currentUser=document.getElementById("")
//if(issueType=="Program Risk" || issueType=="Part Risk" || issueType=="Manufacturing Risk" || issueType=="Quality Risk"||issueType=="Test and Validation Risk"){
switch (issueType) {
case "Program Risk": //if the issue type is Product Engineering
AJS.$(document.getElementById("customfield_16029")).val("sushma.nagaraj");
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj");
//AJS.$(document.getElementById("customfield_15208")).val("peter.savangian"); //set Champion field
break; //end case
// case "BODY": //if the issue type is Test and Validation
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break; //end case
// case "INTERIOR": //if the issue type is Supply Chain
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break; //end case
// // THER IS NO defined sub-program lead for quality, so default to xiao
// case "THERMAL": //if the issue type is Quality
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break; //end case
// case "ENERGY STORAGE AND CHARGING": //if the issue type is Homologation
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break; //end case
// case "CHASSIS": //if the issue type is Finance
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break; //end case
// // THER IS NO defined sub-program lead for Resrouces, so default to xiao
// case "POWERTRAIN": //if the issue type is Resources
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break; //end case
// case "ELECTRICS AND ELECTRONICS": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
// case "USER INTERFACE": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
// case "SOFTWARE": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
// case "EXTERIORS": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
// case "STANDARD PART": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
// case "MISCELLANEOUS": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
// case "MASTER SURFACE": //if the issue type is Manufacturing and Facility
// AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
// //AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
// break;
//end case
}
} //end switch
}); //end change event
} //end prepopulateTeam()
AJS.toInit(function(){ //init function
prepopulateTeam();
}); //end init
}
AJS.$(document).ready(function() {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
function explode(){
function prepopulateTeam(){
/*
Set some of the "Team" fields based on the issueType
The Intiator field is set based on a post funtion script
The Assignee field is set based on a post funtion script
*/
$(document.getElementById("customfield_14041")).change(function(){
issueType = document.getElementById("issuetype-field").value;
system=document.getElementById("customfield_14041").value;
//currentUser=document.getElementById("")
if(issueType=="Program Risk" || issueType=="Part Risk" || issueType=="Manufacturing Risk" || issueType=="Quality Risk"||issueType=="Test and Validation Risk"){
switch (system) {
case "OTHER":
//if the issue type is Product Engineering
AJS.$(document.getElementById("customfield_16029")).val("sushma.nagaraj");
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj");
//AJS.$(document.getElementById("customfield_15208")).val("peter.savangian"); //set Champion field
break; //end case
case "BODY": //if the issue type is Test and Validation
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break; //end case
case "INTERIOR": //if the issue type is Supply Chain
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break; //end case
// THER IS NO defined sub-program lead for quality, so default to xiao
case "THERMAL": //if the issue type is Quality
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break; //end case
case "ENERGY STORAGE AND CHARGING": //if the issue type is Homologation
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break; //end case
case "CHASSIS": //if the issue type is Finance
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break; //end case
// THER IS NO defined sub-program lead for Resrouces, so default to xiao
case "POWERTRAIN": //if the issue type is Resources
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break; //end case
case "ELECTRICS AND ELECTRONICS": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
case "USER INTERFACE": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
case "SOFTWARE": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
case "EXTERIORS": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
case "STANDARD PART": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
case "MISCELLANEOUS": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
case "MASTER SURFACE": //if the issue type is Manufacturing and Facility
AJS.$(document.getElementById("assignee-field")).val("sushma.nagaraj"); //set Assignee
//AJS.$(document.getElementById("customfield_17536")).val("sushma.nagaraj"); //set Champion field
break;
//end case
}
} //end switch
}); //end change event
} //end prepopulateTeam()
prepopulateTeam();
} //end explode
}); //end JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason)
AJS.$(document).bind('dialogContentReady', function(event, dialog) {
setTimeout(explode, 50);
}); //end AJS.$(document).bind('dialogContentReady', function(event, dialog)
}); //end AJS.$(document).ready(function
})(AJS.$); //end (function($)
</script>
The code is unreadable :) Does it work from the browser console?
JS will not work in cloud environment. Are you using the server edition?
I would recommend the behaviours plugin for auto population. JS hacks is not the way to do it in most cases(although I can think of a few exceptions ;).
It is a royal pain in the **** to make JS work with all browsers seamlessly.
I'd echo that, and point out that the ability to execute arbitrary js is gradually (and rightly) being removed from the applications. The only way to reliably run and support js is to package it into an add-on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Danyal,
Thank you for the response. Would you like me to resend the same. Yes, I am using the server edition and it works on the browser console.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Nic,
Thank you for the quick response. Could you please help me as to how I can package it and use it as an add on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.