Default values in custom fields per user

Peter Novak August 11, 2013

Is it possible (via some plugin maybe?) to set defualt values for custom fielde different for each user? :) thank you for answer

5 answers

1 accepted

1 vote
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 Leaders.
September 24, 2013

try with this(for which field type you are trying to set default value)

<script type="text/javascript">  
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
setDefaultValue();    
});
setDefaultValue();
function setDefaultValue(){
        var user=getCurrentUserName();			
		if( user == 'prasad'){
			//	set default value text field, if the field is select list then add option id insted of text
$("#customfield_10571").val('Test');
		}else if(user == 'Ram') {
			AJS.$("#customfield_10571").val('Testing');
		}

}
function getCurrentUserName()
{
var user;
     AJS.$.ajax({
        url: "/rest/gadget/1.0/currentUser",
        type: 'get',
        dataType: 'json',
        async: false,
        success: function(data) {
            user = data.username;
        }
     });
     return user;
}
  
  });

</script>

suggest to load javascript as webresource module in a plugin

Peter Novak September 24, 2013

please, where should i put this code? i am new to scripting in jira

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

first change custom field id and user name

you can load javascript in two ways

1. add it in field description in field configuration

2. load it as webresource module in plugin, check this

https://developer.atlassian.com/display/JIRADEV/Web+Resource+Plugin+Module

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 24, 2013
Peter Novak September 25, 2013

i tried to put this code into field description and it didnt work :(

and isnt there missing "AJS." on the second 1 line?

1 vote
Peter Novak September 24, 2013

hard question i see :)

0 votes
Peter Novak October 2, 2013

i dont need to solve this problem anymore, and cant close it. so i choose one comment as answer

0 votes
MichałS
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 25, 2013

Hi Peter,

You could define the custom field as a scripted field (if you use script runner) and then use groovy to insert the data regarding to the user.

Very simple solution.

Good luck

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

yes, you can write some java script in the velocity template.

you get the option ids from the page and get the user name from $authContext variable and set the restrictions according to that.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events