The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JS to set custom field based on a Project

Adolfo Casari
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 Champions.
July 30, 2013

I would like to set a custom field in the create issue form based on the selection of the project, i.e. if project selected is X, then customfield should be A.

Anyone knows a simple JS (jquery) trick to achieve this?

Thanks in advance.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
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 Champions.
July 31, 2013

try with javascript by adding in any plugin as a webreource or footer.jsp

<script type="text/javascript">
jQuery(document).ready(function($) {
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
		setDefaultValues();
	});
		setDefaultValues();
	
function setDefaultValues(){
		setFieldValue();
	$("#project").change(function() {
		setFieldValue();
	});
}
	
	function setFieldValue(){
		var currentProject=$("#project option:selected").text();
		if(currentProject == 'Test Project'){
			$("#customfield_11329").val('Test');
		}else{
			$("#customfield_11329").val('');
		}
	}

});
</script>

check here to know how to add in plugin

https://answers.atlassian.com/questions/47843/strange-javascript-problem-in-create-screen

Adolfo Casari
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 Champions.
August 4, 2013

Thanks, this works fine.

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 Champions.
July 30, 2013

why you want to do it through JS/Jquery?

you can achive this by using configuring screen scheme for project and you can remove field from create screen, check this document to configure screen scheme

https://confluence.atlassian.com/display/JIRA/Associating+a+Screen+with+an+Issue+Operation

still if you want to do this by using JS, let me know and it is not suggestable

Adolfo Casari
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 Champions.
July 31, 2013

What I need is that if I choose project A in the issue create screen, one customfield in that screen picks automatically a given value, so I don't have to set it manually.

The reason for this is that for that project that custom field is always the same, but for other projects it may change.

TAGS
AUG Leaders

Atlassian Community Events