Custom Field Mandatory for Group

Deleted user March 25, 2014

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

0 votes
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 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.

0 votes
Nadir MEZIANI
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.
March 25, 2014

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


Deleted user March 30, 2014

Sorry, just being dumb...


What sections do I need to change?

Nadir MEZIANI
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.
March 30, 2014

#yourfieldId

Deleted user March 30, 2014

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

Nadir MEZIANI
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.
March 30, 2014

when you cal function checkFieldValue (your_group_name)

Deleted user March 30, 2014

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

Screenshot

Nadir MEZIANI
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.
March 30, 2014

I don't see the screenshot.

Try to debug it with fire bug.

Deleted user March 30, 2014

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>

Deleted user March 30, 2014

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

Nadir MEZIANI
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.
March 31, 2014

hi,

Put all scripts between this tag.

<script type="text/javascript">

all scripts

</script>

Deleted user March 31, 2014
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;

Nadir MEZIANI
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.
April 2, 2014

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

Deleted user April 2, 2014

Yeah I have

Nadir MEZIANI
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.
April 2, 2014

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

Nadir MEZIANI
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.
April 13, 2014

Hi,

What about of your problem?

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2014

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.

0 votes
Deleted user March 25, 2014

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


We're currently running on 6.1.4

0 votes
Deleted user March 25, 2014

That would be perfect!

0 votes
Nadir MEZIANI
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.
March 25, 2014

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.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2014

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.

0 votes
Nadir MEZIANI
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.
March 25, 2014

What is your jira version?

0 votes
Nadir MEZIANI
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.
March 25, 2014

Hi,

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

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2014

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)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events