Hi,
I have Department and Location custom fields on my CREATE ISSUE screen. I want these feilds to be auto populated from my JIRA user's data. e.g. Department as 'IT' and Location as 'USA'.
As of now I am trying this on Custom field. But, could not find any option to auto populate these fileds when the CREATE ISSUE screen is shown.
I also want to make these fields editable as there could be a scenario where user might be working temporarily from a different location and may want to change it from the drop-down or list of values.
Is it achieavable in JIRA? I am little familiar with Groovy scription, but a right direction would be much appreciated.
Regards,
Rumit
Community moderators have prevented the ability to post new answers.
Hi Rumit Patel,
If the auto-population is required only when Create Issue button is pressed, then you directly make that option as default in custom field configuration.
If required based on user data, then you need to write some scripting as prasad mentioned.
Rumit,
you can try with following script by changing as per your requirement
<script type="text/javascript"> jQuery(document).ready(function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { setFieldValues(); }); setFieldValues(); function setFieldValues(){ //get user details here, i am not sure how you will get var department="IT"; var location="USA"; //seting custom field values var departmentField=$("#customfield_10571"); var locationField=$("#customfield_10572"); departmentField.val(department); //set department field value if it is text/text area field locationField.val(location); // set location field value if it is text/text area field //if the field are select list type then call this function setValue(departmentField,department); setValue(locationField,location); } function setValue(field,value){ $(field+" option").each(function() { if($(this).text() == value) { $(this).attr('selected', 'selected'); } }); } }); </script>
Note: don't forgot to update custom field id's
and i suggest to load this javascript using webresource module in a plugin
check this for reference
https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad,
Thank you for the quick response. I am trying to put this code in the 'Description' of the Custom Field (which has a list of values).
Also, I tried a simple alert script and which is also not working.
<script type="text/javascript"> alert('Hi'); </script>
I am putting this script to the 'Description' of my custom field. I tried this script on both List values and Free Text Field custom fields but I don't get an alert pop-up.
My use case:
User clicks on 'Create Issue' and Create Issue screen is displayed.
On this screen, I have a Department and another free text custom field. But I don't get the alert when the screen is displayed.
I saw another article on the link for 'Web Resource', but I am not sure where do I put that code. I am not puting your code in a seperate file, I am just puting it in 'Description' for a custom field.
Is it the right way to do it? It seems to be not working.
Regards,
Rumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you add javascript then it won't work properly on create screen that's why i suggest to add it on aplugin as webresource module. check this
just you need to create a plugin using atlassian sdk and webresource module in atlassian-plugin.xml file
check this document to develop plugin
https://developer.atlassian.com/display/DOCS/Set+up+the+Atlassian+Plugin+SDK+and+Build+a+Project
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you populating these custom fields based on another field? I've asked this because you've mentioned that you want it auto populated from a user's data. If yes, then you might be interested in the following two links
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Zulfadli (I hope im referring you correctly :))
The link that you gave suggest to use the Groovy Script which I am already using. However, I don't see any option to acheive what I am looking for. I checked the built-in scripts and some customized scripts, but most of them suggest 'how to update a field' on the transition/post-funtion.
What I am looking for is an on-screen update of the feilds. I would add some more light here on my use case.
When user clicks 'CREATE ISSUE', its screen is shown with relevant fields. On this screen, I have Department and Location custom fields (with some list of values). I have these values set for each user (in JIRA user metadata) in the JIRA database. So when this CREATE ISSUE screen is launched, I want these two feilds to be auto-populated on the screen. SO, I am not going throuhg any transition/postfuntion yet.
I hope this helps understand my problem. Feel free to add your suggestions.
Regards,
Rumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this can be achived by using Javascript and REST and from whre you will get Department and Location attributes i haven't seen on user profile.
i am not sure how to do it by using script runner, may be some one will help you!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasad,
I am fine exploring other scripting options.
Thanks for the info, but I am not familiar with Javascript in JIRA. I am familiar with JAvascript in other frameworks e.g. .Net. So it would be really great if you could give some more detail on your solution. A sample script would be of great help.
For the user data, it is actually a user meta data (key - value pairs), So I would have 'Department' as a key and 'IT' as a value for a given user metadata.
Regards,
Rumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a use case for behaviours plugin not script runner. But javascript as ram says is also a perfectly viable option.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.