I've written a small piece of javascript that automatically fills in the Summary field when creating a new issue. This works as intended when I open the "Create Issue" screen by right-clicking the "Create" button and opening it in a new tab or window. However, my script doesn't work when I open the screen by just clicking on it and opening the dialog.
How can I get my javascript to work in the "Create Issue" dialog?
Below is my javascript:
jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { autoFillSummary(); }); autoFillSummary(); // Automatically fill the summary field with a default value. function autoFillSummary(){ var issueType = $('#issue-create-issue-type').text(); var reporter = $('#reporter').val(); var d = new Date(); d = d.toDateString(); var summaryVal = reporter + " - " + "[ " + d + " ]"; if(issueType === "Job"){ $('#summary').val(summaryVal); $('#summary').closest('div.field-group').hide(); $('#reporter').closest('div.field-group').hide(); } } });
Thank you for your help.
Community moderators have prevented the ability to post new answers.
Hi!
First you need to be sure that Create issue dialog ready.
You could use timeout
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { setTimeout(function() {autoFillSummary();}, 50); });
Second, there is no such element $(
'#issue-create-issue-type'
) in dialog but there is $('#issuetype').
Thank you for the response. This doesn't do the job unfortunately. For now, I've worked around the issue by using [code]AJS.$("#create_link").removeClass("create-issue");[/code] to disable the pop-up window and force the Create Issue screen into a new page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks not good. You could find the bug in your code via debugging JavaScript https://developer.chrome.com/devtools/docs/javascript-debugging Maybe there is no $('#issuetype') too in your JIRA version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My debugging efforts seem to indicate that the script isn't firing when the "create issue" dialog open. Also, you're right, in the JIRA version I'm using, the element id is $('#issue-create-issue-type'). $('#issuetype') doesn't seem to work for me but as a precaution, I've added it to the condition as an OR expression. I'm new to JQuery and JIRA so the problem is likely due to my lack of knowledge but I have feeling the solution is rather straight-forward.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Dmitrii, Your suggestion is perfectly working. Thanks for your work around !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I must apologize, Dmitrii, your solution was correct. My error was in what id I was using. For the "Create Issue" dialog, I had to use: AJS.$('#issuetype-field').val(); For the "Create Issue" page, I had to use: AJS.$('#issue-create-issue-type').text(); Now it's working perfectly. Thank you for your help. Much appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All, I have the opposite case. My javascript only be called in "create issue" dialog but not "create issue" in new tab or new window. Here is the simplified version of my javascript. jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) { alert("create"); }); alert("create in new window"); }); When creating an issue in the dialog, "create" message is shown. When creating an issue in new tab or window, no alert message is shown. When searching issues, "create in new window" message is shown. It seems the javascript is not invoked when creating issue in new tab or window. Please help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try this? jQuery(document).ready(function() { if (String(document.location.href).indexOf("CreateIssue.jspa") >= 0) { alert('') } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srinivas, Thanks for your reply. I tried your suggestion but the alert message is still not shown in new tab or new window when creating issue. I think the javascript is not loaded in this case. By the way, I have my javascript as a web-resource of a plugin which I added to my JIRA instance. I am not sure if that changes anything.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the web resource I defined in my plugin. <web-resource key="javascriptplugin-resources" name="javascriptplugin Web Resources"> <dependency>com.atlassian.auiplugin:ajs</dependency> <context>atl.general</context> <resource type="download" name="javascriptplugin.js" location="js/javascriptplugin.js"></resource> </web-resource>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try this and see if this is working? jQuery(document).ready(function() { alert((document.location.href).indexOf("CreateIssue.jspa") ) }); My JS is working is same way but I am not injecting as dependency. In our case it was simple hack so we are calling from JS file from Announcement banner.
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.