Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira behavior not... behaving; works in some cases and not others.

Mike Rathwell
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.
August 27, 2019

I have a use case where the project owners want a "disclaimer" message field displayed on issue create to all Jira users aside from those in their Jira user group. It correctly, doesn't appear if one is in the group that doesn't want to see it. However, the disclaimer will display correctly only if one lands directly on an issue create screen for that particular project. Also, if one changes the issue type, or changes to another project and back to the one that wants the disclaimer, it won't reappear.

The behavior is below. I have a log.debug in there that throws the true/false statement in the logfile. It is correctly evaluating whether the disclaimer field should display or not but I still get the "not" displayed when I really want it to as described above.

Any ideas?

import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.component.ComponentAccessor

def disclaimWarn = getFieldById("customfield_17206")
def aGroup = ComponentAccessor.groupManager.getGroup("groupBeingChecked")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName()
def inGroup = ComponentAccessor.groupManager.getUserNamesInGroup(aGroup).contains(currentUser)
log.debug "${inGroup}"
if (inGroup) {disclaimWarn.setHidden(true)}
else {disclaimWarn.setHidden(false)}

1 answer

0 votes
Ilya Turov
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.
August 27, 2019

Hello,

do you have it as an initializer or as a field script? I feel like 2nd option should work

Also, better way to check if user is in group is by using this method:

def inGroup = groupManager.isUserInGroup(ApplicationUser user, String groupName)
Mike Rathwell
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.
August 27, 2019

Hi @Ilya Turov ,

I should've mentioned; I have this in as a server side script. I do not however have this in as an initializer. Perhaps I should put the same script in both places?

Mike Rathwell
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.
August 27, 2019

Dang... thought you might have been onto something. I put that same script (albeit without your very good suggestion) in the initializer and... same result. The validation still validates correctly  but the results cited above still are present.

Ilya Turov
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.
August 28, 2019 edited

Hey, I didn't have access to jira yesterday, but now I've got to it and tested.

Dunno what's really happening in your behaviour, but for me it worked.

Do you per chance have this field hidden in a field configuration? Because I believe behaviour won't override it, that's my only educated guess.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, ace, atlassian community event, donation, girls who code, women in tech, malala fund, plan international, kudos, community badge, badge, atlassian badge, International Women’s month, International Women’s Day, women's month, women's day

10 for Change at Atlassian Community Events

Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!

Join an Atlassian Community Event!
AUG Leaders

Upcoming Jira Events