In a field configuration for one of our projects, we have the following in the Summary description:
<script type="text/javascript">
AJS.$("#summary").val("Group Membership Request");
</script>
In the create screen, sometimes the Summary field gets pre-populated and sometimes is doesn't.
Any ideas?
I don't know javascript to save my life. I copied and pasted this from some other source. I'm happy to solve this some other way.
Thanks.
Have you tried putting your code in the announcement banner instead?
That would be okay.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
btw. this might also overwrite the summary on edit issue page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
possible reason:
your javascript code is running when the DOM document (page) is still rendering.
Sometimes youre lucky and the element with id #summary has already been rendered. Then your script is picking it up and rewriting the value as intended.
Sometimes however it is possible that the #summary element has not been rendered when your script is running. Therefore it is unable to locate the #summary element and does nothing.
possible solution:
try embracing the population code into document.ready event handler.
this ensures, that the script is running only when the page has finished rendering.
<script type="text/javascript"> AJS.$(document).ready(function() { AJS.$(document).bind('dialogContentReady', function(event, dialog) { AJS.$("#summary").val("Group Membership Request"); }); }); </script>
PS: Elements that appear in pop up dialogs are missing even when document is finished rendering.
To pick them you should bind your preopulation code to dialogContentReady event.
Try this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So far so good! THX!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I spoke too soon. :( Not fixed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
same behavior or doesn't work at all? are there any javascript errors in 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.
i have changed the example code for your-temlate. Try binding your prepopulation code to dialogContentReady event. If the summary field is coming in a popup dialog, it is accessable only after dialogContentReady event.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
also watch out for javascript console of your browser. It often tells you what is wrong. if it cannot pick element by id, you will see an error there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The new code did not work. In fact, it wouldn't render anything at all. I went back to my original code and now it won't fail. I'm sure it will eventually. No errors from javascript console when using your new javascript.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure you don't have more than one element with ID "summary" on the page? Can you debug it, as when it does not set the field, try to open console (like in Chrome Developer tools) and type AJS.$('#summary') How many elements you will get back?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this. I only got one element back. [<input class="text long-field" id="summary" name="summary" type="text" value>] It did not populate the Summary field btw. I have noticed that it seems to always work after I have brought up one create pop-up and either canceled it or created the new issue. The next time the create pop-up arrives, the summary field is populated. Furthermore, when it is correctly populating the summary field, it in-correctly populates the summary field for every issue I go to create. Regardless of project or issue type. Even tho this javascript is in the description for Summary in a field configuration only used for one issue type in one project. I'm definitely doing something wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>I have noticed that it seems to always work after I have brought up one create pop-up and either canceled it or created the new issue. The next time the create pop-up arrives, the summary field is populated. this clearly indicates that my assumption was right. Your script is running at wrong time, when the element does not exist. let me explain: all the popup dialogs, (such as create-issue or edit-issue) are being rendered dynamically when user clicks according button. Once rendered, they are not getting removed, but hidden. They are still there but unvisible after first call. first time your script is running after rendering issue-view page when the #summary element is missing. Nothing happens. once you open a pop-up (click edit), the content of the dialog is rendered into the page and #summary appears for first time. But there is no javascript action going on at this time. once you have canceled a popup, it remains in the background. So when your script is being processed next time, the summary element is available.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do I fix this? Here's what I want. For this issue type, in this project, I want to pre-populate the summary field. What's the best way of doing that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
well populating summary for specific issue type and specific project will require more logic then just setting value for #summary. the code i have posted should make it possible to synchronize script processing with popup dialogs. there might be something else broken which prevents you from running the script. I would suggest declaring the script as ressource in global context. Then you can debug it and see if it is running at all, when it is running and whether it can see #summary element during runtime. you do it by putting the java code into .js file in main/resources folder and declaring it as webresource in main/atlassian-plugin.xml see documentation https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
alternatively you can use javascript file that is already declared as default webresource for your plugin. just dont forget to give it a global context. Otherwise the script will not be loaded into default jira pages. Something like <context>atl.global</context> more about context https://answers.atlassian.com/questions/10343/web-resource-contexts
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.