Update field based on Issue type Edited

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

1 vote
Tayyab Bashir Community Champion Sep 08, 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()
})

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 Community Champion Sep 08, 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.  

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 Community Champion Sep 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. 

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.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,221 views 14 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot