Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I write a condition to only have a UI Fragment show up for users in a specific group?

Miranda
February 2, 2026

I was able to write a condition for a UI item within Jira fairly easily:

 

def user = Users.getLoggedInUser()

user.isMemberOfGroup("name-of-group")
However, when I'm trying the same thing within Confluence, it doesn't work...
Can someone help me understand why Confluence and Jira are different and how I can write a condition within Confluence that works?
Thanks for all your help!
PS: This is for Data Center, not cloud

1 answer

1 accepted

1 vote
Answer accepted
Evgenii
Community Champion
February 2, 2026

Hi, @Miranda 

Welcome to Atlassian Community!

In Confluence Java API has methods, which differ from Jira.
Code, which makes the same in Confluence, looks like:

import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.sal.api.component.ComponentLocator

def crowdService = ComponentLocator.getComponent(CrowdService)
crowdService.isUserMemberOfGroup(context.currentUser?.name, "confluence-administrators")
Evgenii
Community Champion
February 2, 2026

It's in example scripts, you can check it by yourself, and find many other useful examples:
chrome_020226_922.pngchrome_020226_921.png

Miranda
February 2, 2026

@Evgenii thank you so much for your help!

Sorry, I should have mentioned this in my original post, I tried the example script but am receiving an error:

[Statis type checking] - Cannot find matching method .com.atlassian.crowd.embedded.api.CrowdService#isUserMemberOfGroup(java.lang.Object, java.lang.String). Please check if the declared type is correct and if the method exists. 

[Static type checking] - No such property: name for class: java.lang.Object

ConfluenceConditionError.png

This is in a dev environment, I haven't tried it in a Prod environment. I don't know if that could cause an issue?

Miranda
February 2, 2026

This ended up working for me, I'm not sure why the example script didn't or why this one does...

 

import com.atlassian.crowd.embedded.api.CrowdService
import
com.atlassian.sal.api.component.ComponentLocator

def user = Users.getLoggedInUser().name

def crowdService = ComponentLocator.getComponent(CrowdService)

crowdService.isUserMemberOfGroup(user, "confluence-administrators")
Evgenii
Community Champion
February 2, 2026

Hi, @Miranda 

Static errors usually are not very important, just annoying, and they don't influence on script execution. But if you also don't like red text (like me), if you want to get rid of such errors, you need to explicitly assign object types.

Like this, for example:

import com.atlassian.confluence.user.ConfluenceUser
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.sal.api.component.ComponentLocator

CrowdService crowdService = ComponentLocator.getComponent(CrowdService)
crowdService.isUserMemberOfGroup((context.currentUser as ConfluenceUser)?.name, "confluence-administrators")

Or, if you want error safe version, when someone anonymous opens page, you can use this:

import com.atlassian.confluence.user.ConfluenceUser
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.sal.api.component.ComponentLocator

ConfluenceUser currentUser = context.currentUser as ConfluenceUser
if (!currentUser) {
return false
}

CrowdService crowdService = ComponentLocator.getComponent(CrowdService)
return crowdService.isUserMemberOfGroup(currentUser.name, "confluence-administrators") 

BTW, context.currentUser - it's UI fragments specific variable. 
Your method, using 
Users.getLoggedInUser().name is more generic.

Miranda
February 3, 2026

Thank you so much for your answers! This is all great knowledge to have, I really appreciate your help!

Like Evgenii likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events