executing a script(worklog attribute) for the users of a particular group

Hi,

I have a script which checks some check box and puts in some values in the logwork tab fields.

But now I want that script to execute(check and put values), only for a particular group members

i.e if the user belongs to that particular group ,then only that script should check the checkboxes and put default values i the log work fields.

How can I modify my script?Any ideas ?

Thanks in advance.

Regards,

Asif

3 answers

This widget could not be displayed.

script shuld not execute for other group members.

example: if there are two groups: group A and B.

then whenever a member of group A logs work, that script should check the check boxes and put default values in the fields of the log work tab. But if members of group B log work, script should not check the checkboxes and should not put values in the fields.

This widget could not be displayed.
Henning Tietgens Community Champion May 05, 2014

You could check the groups of a user using userUtil.getGroupsForUser().

jQuery(document).ready(function() {

var project_name = $('#project-name-val').text();

var user_group=$(userUtil).getGroupsForUser();
alert(+user_group);



{

//var user_name = $('#user-name-val').text();
//var assignee_name= $(' #assignee-name-val').text();
//alert(+project_name);
//var user_group=$(userUtil).getGroupsForUser();


if(user_group == ('group1')
{
window.alert('Message goes here');
$('#popup_type1_').attr('checked','checked');
$('#popup_type2_').attr('checked','checked');
$('#popup_type3_').val('0');
}


});

again, i want to check is the user belong to group 1.what changes i should make in he code. am i using the getgroupsforuser method correctly?if not, could you please show me the right way?

thanks in advance

Henning Tietgens Community Champion May 06, 2014

Oh, I thought your are talking about a Java or Groovy script...

The method is documented here, you have to provide the user name as an argument. But I don't know if userUtil is available within the velocity context and how to process the returned SortedSet of Groups in velocity.

Henning Tietgens Community Champion May 06, 2014

If userUtil is available it should be possible...

Henning Tietgens Community Champion May 06, 2014

As of https://developer.atlassian.com/display/JIRADEV/Contents+of+the+Velocity+Contextit should be available as "userutil". And the user as remoteUser, so remoteUser.name should be the user name.

so this method cannot be used in this script?

but the contents of velocity is for modifying the the email template as per the doc.will it work for this case also?

Henning Tietgens Community Champion May 06, 2014

I don't know, did you tried it? The page says "Velocity Context used to process web templates", so it's not only email templates.

jQuery(document).ready(function() {

var project_name = $('#project-name-val').text();

alert(+project_name);

var user_group=$(userUtil).getGroupsForUser();

alert(+user_group);

 

if(project_name == 'abcd')

{

window.alert('Message goes here');

$('#popup_a1_').attr('checked','checked');

$('#popup_b1_').attr('checked','checked');

$('#popup_c1_').val('0');

}

});

in the above code i have used userutil.getgroupforuser method.but iam not sure i am usng it the right way.if i had used it right, i should have got user_group in the alert.but iam not gettingit. also, i have not included/defined userutil anywhere in code.without the fourth line of the code, the code works fine.but i want to extract the group name of the user and then use it further in my code.

Thanks alot for your help so far.

Henning Tietgens Community Champion May 06, 2014

You have to provide the user name as argument of getGroupsForUser(). I'm not an velocity expert, but I think you have to write

$userutil.getGroupsForUser($remoteUser.name)

to get the groups.

This widget could not be displayed.

jQuery(document).ready(function() {

var project_name = $('#project-name-val').text();

var user_group=$(userUtil).getGroupsForUser();
alert(+user_group);



{

//var user_name = $('#user-name-val').text();
//var assignee_name= $(' #assignee-name-val').text();
//alert(+project_name);
//var user_group=$(userUtil).getGroupsForUser();


if(user_group == ('group1')
{
window.alert('Message goes here');
$('#popup_type1_').attr('checked','checked');
$('#popup_type2_').attr('checked','checked');
$('#popup_type3_').val('0');
}


});

again, i want to check is the user belong to group 1.what changes i should make in he code. am i using the getgroupsforuser method correctly?if not, could you please show me the right way?

thanks in advance


Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday 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...

178 views 1 3
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