Custom Field Mandatory for Group

On the Create screen for issues, is it possible to set a Custom Field to be mandatory for one group of users and not others?

10 answers

1 accepted

This widget could not be displayed.
Tarun Sapra Community Champion Mar 30, 2014

If it's a hosted version of jira that you are using, then why don't you just write a small groovy script using script runner plugin and put that in the validation phase of the create issue transition.

Javascript messes up jira.

This widget could not be displayed.

No, mandatory in plain Jira is an immensely simple flag. You either require a field on the issue type or you do not.

The standard approach here is a validator that reads the current users groups and checks that the field is filled as they create the issue. You'll need to find or write one to do that (I'd use the script runner)

This widget could not be displayed.

Hi,

if you are interested, i can give you a javascript code that can help you to do it.

This widget could not be displayed.

What is your jira version?

This widget could not be displayed.

Please bear in mind that javascript is not a good idea in Atlassian apps. It's hard to get it right if you use more than one script because of the interference that can happen, it routinely fails and can become a nightmare on upgrades, and it's a doddle to bypass it if your users want to. (On the other hand, I've had quite a lot of work out of "please sort out our system by removing the javascript hacks")

In other words, keep javascript tricks to a minimum and avoid them whereever you can.

This widget could not be displayed.

Hi

I quite agree with you @Nic Brough, I already had a lot of problems, but we still use it. Sometimes, we have an only solution which is javascript.

This widget could not be displayed.

That would be perfect!

This widget could not be displayed.

Yeah I completely agree, luckily it's on a issue type that has little else happening.


We're currently running on 6.1.4

This widget could not be displayed.

Yes, hence the note of caution (rather than a couple of things people do where I end up screaming "no"). If you keep it light and minimal, you'll probably be ok.

This widget could not be displayed.

Put scripts in the description of your custom field or preferably put in a plugin WebResources (to develop)

Try this scripts

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

//get groups of the user logged in 
function getNameGroups(user)
{
var groups=[];
AJS.$.ajax({
url: contextPath+"/rest/api/2/user?username="+user+"&expand=groups",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
AJS.$(data.groups.items).each(function(i){groups.push(data.groups.items[i].name);});
}
});
return groups;
} 

// check if user in the group
function userInGroup(user, group){
var groups = getNameGroups(user);
return (AJS.$.inArray(group,groups)>-1) ? true:false;
} 
//check field value user group 
function checkFieldValue(fieldValue,user,group){
	if(fieldValue=="" && userInGroup(user, group)){//you can put more conditions
		alert ("Please, put some values");
	}
}
//associate the function to event 
AJS.$(document).ready(function(){
if (AJS.$('#issue-create-submit').length>0){
AJS.$('#issue-create-submit').mouseover(function (){checkFieldValue(AJS.$('#yourfieldId').val(),getCurrentUserName(),your_group_name);}) //validate with mouse
}})

you can associate other events


Sorry, just being dumb...


What sections do I need to change?

Where do I specify the group that a user should be in?

when you cal function checkFieldValue (your_group_name)

Am I missing something in the code as it's showing up when I create an issue

Screenshot

I don't see the screenshot.

Try to debug it with fire bug.

Debug showed:

<div class="field-group aui-field-cascadingselect">
<label for="customfield_11815">APS Remedy Categories</label>
<select id="customfield_11815" class="select cascadingselect-parent" name="customfield_11815">
<select id="customfield_11815:1" class="select cascadingselect-child" name="customfield_11815:1">
<div class="description">//get current user logged in function getCurrentUserName(){ var user; AJS.$.ajax({ url: contextPath+"/rest/gadget/1.0/currentUser", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.username; } }); return user; } //get groups of the user logged in function getNameGroups(user) { var groups=[]; AJS.$.ajax({ url: contextPath+"/rest/api/2/user?username="+user+"&expand=groups", type: 'get', dataType: 'json', async: false, success: function(data) { AJS.$(data.groups.items).each(function(i){groups.push(data.groups.items[i].name);}); } }); return groups; } // check if user in the group function userInGroup(user, group){ var groups = getNameGroups(user); return (AJS.$.inArray(group,groups)>-1) ? true:false; } //check field value user group function checkFieldValue(fieldValue,user,group){ if(fieldValue=="" && userInGroup(user, group)){//you can put more conditions alert ("Please, put some values"); } } //associate the function to event AJS.$(document).ready(function(){ if (AJS.$('#issue-create-submit').length>0){ AJS.$('#issue-create-submit').mouseover(function (){checkFieldValue(AJS.$('customfield_11815').val(),getCurrentUserName(),IS Monitoring);}) //validate with mouse }})</div>
</div>

I will attempt to look at fire bug, in the mean time the screenshot shows the entire script in the description as if it was just plain text

https://dl.dropboxusercontent.com/u/7609815/WebLinks/31-03-2014%2016-33-06.jpg

hi,

Put all scripts between this tag.

<script type="text/javascript">

all scripts

</script>

So I'm now using the below, but it's still allowing me to create issues even though I am in the Support group in JIRA

&lt;script type="text/javascript"&gt;
//get current user logged in
function getCurrentUserName(){
var user;
AJS.$.ajax({
url: contextPath+"/rest/gadget/1.0/currentUser",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data.username;
}
});
return user;
} 
 
//get groups of the user logged in 
function getNameGroups(user)
{
var groups=[];
AJS.$.ajax({
url: contextPath+"/rest/api/2/user?username="+user+"&amp;expand=groups",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
AJS.$(data.groups.items).each(function(i){groups.push(data.groups.items[i].name);});
}
});
return groups;
} 
 
// check if user in the group
function userInGroup(user, group){
var groups = getNameGroups(user);
return (AJS.$.inArray(group,groups)&gt;-1) ? true:false;
} 
//check field value user group 
function checkFieldValue(fieldValue,user,group){
    if(fieldValue=="" &amp;&amp; userInGroup(user, group)){//you can put more conditions
        alert ("Please, put some values");
    }
}
//associate the function to event 
AJS.$(document).ready(function(){
if (AJS.$('#issue-create-submit').length&gt;0){
AJS.$('#issue-create-submit').mouseover(function (){checkFieldValue(AJS.$('customfield_11815').val(),getCurrentUserName(),Support);}) //validate with mouse
}})
&lt;/script&gt;

have you put this scripts in the description of a custom field?

Try to put you group name between "" like this "Support".

Hi,

What about of your problem?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

67 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you