Update field based on Issue type

Piyush_Annadate September 6, 2017

Requirement: Update 'Description' field based on Project (A) and Issue type

Project have their own Screens/Fields configurations

Issue Type - ~9; requirement to be applied to only 5

( Project A - applied configuration to; Project B - Nothing touched)

Below codes are working; but bugs are

1. While creating issue; project A is selected and issue type (any of 5) - description field is populated as expected

2.  If project selection is changed from A to B - description field is still populated with old data

3. Description field should be refreshed as EMPTY as other project doesn't have any data/value to be populated in Description field.

 

 

Banner:


<script type='text/javascript'>
AJS.toInit(function () {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
jQuery("#issuetype-field").on("change", function () {
Despacito()
})
JIRA.bind(JIRA.Events.ISSUE_REFRESHED, function (el, cont) {
Despacito();
})
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, cont, reason) {
if (reason === JIRA.CONTENT_ADDED_REASON.dialogReady) {
Despacito();
}
})

JIRA.bind(JIRA.Events.INLINE_EDIT_SAVE_COMPLETE, function (e, context) {
Despacito();
})

JIRA.bind(JIRA.Events.INLINE_EDIT_STARTED, function (e, context) {
Despacito();
})
});
});
</script>

 

Description field: "DESCRIPTION OF DESCRIPTION FIELD IS UPDATED TO BELOW SCRIPT"

<script type="text/javascript">
if(document.getElementById("edit-issue-dialog")==null)
Despacito()
function Despacito() {
descriptionF = document.getElementById("description");
if(document.getElementById("create-issue-dialog")!=null)
descriptionF.value=" ";
if (document.getElementById("project-field") != null)
{
if (document.getElementById("project-field").value == null)
projectName = document.getElementById("project-field").innerHTML;
else
projectName = document.getElementById("project-field").value;
} else
{
if (document.getElementById("issue-create-project-name").innerHTML == null)
projectName = document.getElementById("issue-create-project-name").value;
else
projectName = document.getElementById("issue-create-project-name").innerHTML;
}
if (projectName == "NS Delivery Change Planning (DCP)" || projectName=="NS Delivery Change Planning")
{
descriptionF.value=" ";
if (document.getElementById("issuetype-field") == null)
issueType = document.getElementById("issue-create-issue-type").innerHTML;
else
issueType = document.getElementById("issuetype-field").value;

if (issueType == "Training Request") {
descriptionF.value = "some data";
} else if (issueType == "Agenda Proposal") {
descriptionF.value = "some data";
} else if (issueType == "CRI – Request Transfers") {
descriptionF.value = "some data";
} else if (issueType == "Maintenance") {
descriptionF.value = "some data";
} else if (issueType == "Change Request") {
descriptionF.value = "some data";
} else {
descriptionF.value = " ";
}
}
}
</script>

 

1 answer

1 accepted

2 votes
Answer accepted
Tayyab Bashir
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.
September 8, 2017

Add these calls along with NEW_CONTENT_ADDED as well

 Despacito()
setTimeout(hidePriorityField , 150)
JIRA.bind(JIRA.Events.ISSUE_REFRESHED,function(el,cont){
Despacito()
})
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED,function(e,cont,reason){
if(reason === JIRA.CONTENT_ADDED_REASON.dialogReady){
Despacito()
}
})

JIRA.bind(JIRA.Events.INLINE_EDIT_SAVE_COMPLETE,function(e,context){
Despacito()
})

JIRA.bind(JIRA.Events.INLINE_EDIT_STARTED,function(e,context){
Despacito()
})
Piyush_Annadate September 8, 2017

what does 'reason' should be here and also how can make sure banner script will be running only where issue-create-dialog is open? Anyhow- i want it to run on both new tab and dialog box open scenario. 

Tayyab Bashir
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.
September 8, 2017

If you want the script to run only on issure-create-dialog then you would need to put a condition check on it.

surround your scrpit with 

<script>
(function($) {
// This is for when an issue is being created while
// opened in a new window tab
AJS.toInit(function(){
if (AJS.$("#issue-create-submit").val()=="Create" || AJS.$("#create-issue-submit").val()=="Create"){
// Your code
}
})

// This is when issue is being created via dialog box popup.
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
if (AJS.$("#issue-create-submit").val()=="Create" || AJS.$("#create-issue-submit").val()=="Create"){
// your code.
}
});
})(AJS.$);
</script>

This will also take care when project is switched from A to B.
Ignore the above Events.

Wrap your code and adjust it into this.  

Like Suhail Falak likes this
Piyush_Annadate September 11, 2017

Tayaab,
I've added your 1st provided function to banner  - Question code updated

THIS IS WORKING AS ALL GOOD ON BOTH THE CREATE SCREEN; but discovered something else

When I'm on Issue View screen and try to edit -
* On 1st click - Edit dialog box is opening as normal
* Then if I cancel/Escape it and click on 'Edit' again - it just shows 'loading indicator' continous without any stop.
* Until and un-less page is refresh - edit box isn't getting opened.

Tayyab Bashir
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.
September 12, 2017

Hmm, this is wierd behaviour. 
Because the JavaScirpt in your code doesn't even target the Edit Screen. 
The submit value button on "Edit" screen, is Update, while in the both of our If Conditions, we are telling it to run where id = issue-create-submit. 
So it shouldn't even run over there. 

Maybe try deleting the browser Cache and then trying it again. 
Because sometimes it does messes up with JavaScript. 

Piyush_Annadate February 1, 2018

Hi Tayyab,

Now, we've upgraded to 7.3 wherein we've Visual/Text mode for description field.  Now when the issue is selected the description field isn't getting populated properly.

Junio Fernandes August 24, 2018

Hi! I'm running an adapted version of this script,  for summary field, on Jira Server 7.11.

Works Great! 

I putted all the javascript on banner.

Tks.

Vineela Durbha September 29, 2020

@Tayyab Bashir 

I have below javascript to set description value, but the description field is not clearing when I am changing the project. Can you help on this if you have any ideas

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context, reason) {


var project = AJS.$('#issue-create-project-name').text();
var projectn = AJS.$('#project').val();

var isCreateIssuePage = AJS.$('#create-issue-dialog').is(':visible');
var itype =AJS.$('#issue-create-issue-type').text();
var issueType = AJS.$('#issuetype-field').val();


if(project == 'Support - Lifecycle Tools' || projectn =='11805'){
//alert('lcsppt')
if (issueType == "Defect" || issueType == "Task" || itype == "Defect" || itype == "Task"){
//alert('itype')
if (isCreateIssuePage == true || AJS.$('#content .aui-page-header-main h1').text() == "Create Issue") {

if (document.getElementById("description").value =="") {
//alert('nodesc')

AJS.$("#description").val("<b>Context</b><h3>What is the requested change?</h3> \n <p>&ltdescribe the request here&gt</p> \n<h3>Why is this change needed?</h3> \n <p>&ltdescribe the motivation here&gt</p> \n<h3>What is the impact to existing process, tools, and stakeholders? </h3>(if known): \n <p>&ltdescribe the impact here&gt</p> \n<h3>Steps to perform/reproduce </h3> \n <p> <ol class= olnospace>&ltList the planned activities or steps to reproduce the fault (defects only)&gt</ol></p> \n<h3>Acceptance Criteria </h3> \n <p>&ltList the expected output to be completed before this ticket can be closed&gt </p> ");
}
}
}
}else{

AJS.$("#description").val("");

}
});

Suggest an answer

Log in or Sign up to answer