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

asif khan May 5, 2014

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

0 votes
asif khan May 6, 2014

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


0 votes
Henning Tietgens
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.
May 5, 2014

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

asif khan May 6, 2014

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
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.
May 6, 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
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.
May 6, 2014

If userUtil is available it should be possible...

Henning Tietgens
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.
May 6, 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.

asif khan May 6, 2014

so this method cannot be used in this script?

asif khan May 6, 2014

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
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.
May 6, 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.

asif khan May 6, 2014

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
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.
May 6, 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.

0 votes
asif khan May 5, 2014

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.

Suggest an answer

Log in or Sign up to answer