Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA: How to populate a custom field value from JIRA user data on Create Issue screen

Rumit Patel September 11, 2013

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

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Bharadwaj Jannu
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, 2013

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.

1 vote
RambanamP
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 11, 2013

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

Rumit Patel September 12, 2013

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

RambanamP
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, 2013

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

https://developer.atlassian.com/display/JIRADEV/Custom+Fields+that+use+CSS+or+JavaScript+Web+Resources+in+JIRA+5.0

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

0 votes
Zul NS _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 11, 2013

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

Rumit Patel September 11, 2013

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

0 votes
RambanamP
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 11, 2013

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!!

Rumit Patel September 11, 2013

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

JamieA
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, 2013

This is a use case for behaviours plugin not script runner. But javascript as ram says is also a perfectly viable option.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events