Could anyone help with a script for conditional execution in a post function?

I am attempting to allow a specific group to by pass a workflow step.  I want the script to get the current user and if that user is in a group "QA" , it returns true and the post function executes the next transition. 

I'm not sure what to do for coding here. I've attempted to use groovy but our script listener add on is broken at the moment and I cannot test. 

Any help would be greatly appreciated in making this code work.

thanks,

import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.ComponentManager;

User user = ComponentManager.getInstance().getJiraAuthenticationContext().getLoggedInUser();
CrowdService cs = ComponentManager.getInstance().getCrowdService();
return cs.isuserMemberOfGroup(user.getName(), "QA");

1 answer

1 accepted

0 vote

Try:

def groupManager = ComponentAccessor.getGroupManager()
return groupManager.getGroupNamesForUser(user.name).contains("QA")

@echlin I was getting this error when it ran. I was able to pull it out of catalina.out when creating a ticket. Script1.groovy: 5: unable to resolve class CrowdService @ line 5, column 14. CrowdService cs = ComponentManager.getInstance().getCrowdService(); So I added this import: import com.atlassian.crowd.embedded.api.CrowdService; That didnt seem to help. Any help would be greatly appreciated.

Strange... Try def groupManager = ComponentAccessor.getGroupManager() return groupManager.getGroupNamesForUser(user.name).contains("QA")

that worked. thank you so much.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

359 views 0 6
Read article

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