Hi...I am writing a script listener that triggers when there is a change in the Assignee field. When the Assignee field is not null, I need to check if the Assignee is member of certain groups to appropriately set the value of a check box custom field. I dont know how to do the part when I have to check if the Assignee is member of a group(s). Can anybody assist? This is for scriptrunner for cloud.
Thank you
Hi Tomas,
Thank you for your question.
I can confirm that the example code shared above will not work inside of Jira Cloud due to the fact that Atlassian only provide a Rest API in Jira Cloud and not the same Java API that the server version contains.
You can see more detailed information on the differences between ScriptRunner for JIRA Cloud and ScriptRunner for JIRA Server inside of the documentation page located here.
In order to check if a user is a member of a group inside of ScriptRunner for Jira Cloud you will need to call the group rest API located here in order to return all the members for the group so that you check if a specific user exists inside the members are returned.
I can confirm that I have a sample script located here which shows how you can call the group rest API to return all members of a group and then to check if a specific user exists inside of that group.
You will be able to take this example and will be able to modify it to achieve your requirements.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kristian Walker _Adaptavist_ I have a question regarding permissions...the script listener that I configured is checking if the Assignee field is changed and then check membership of the new Assignee to set the value of a custom field. I want the script listener to trigger everytime any user changes the value of the Assignee field. Since the group rest API requires jira admin permission, if the script listener is run as Current User, the script listener throws a permission error. I can of course set the script listener to run as the scriptrunner add-on user but then the history tab of the jira issue would indicate the custom field was updated by the scriptrunner add-on user instead of the actual user. Is there a workaround for this situation?
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tomas,
Unfortunately, there is no workaround for this as the Rest API mandates that a user must have admin permissions, so for current users, you will only be able to execute the script if a user is an admin user.
This a limitation of the API and is not something that ScriptRunner can work around.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kristian Walker _Adaptavist_ ...understood...so I have a question/suggestion...is there a way to have a line of code within the script to execute the put (the line that set the value of my custom field) as the current user so that way even though the script listener is configured to execute as the scriptrunner add-on user, that specific line of code (the update of the custom field) is executed as the current user? As I explained, my script verifies assignee membership (which I understand requires admin permissions, that is why the script needs to be executed as the scriptrunner add-on user), and then, based on assignee membership, a custom field is set to a value, that function (put("/rest/api/2/issue/${issue.key}")) would not require admin permission, so could I somehow add a line in the code so the put is performed as the current user instead? Just thinking out loud here :-)
Once again, thank you for all your assistance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI Tomas,
Unfortunately, it is not possible to add a line of code to execute the update as another User as the Atlassian Rest API's do not permit this.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Kristian_Walker__Adaptavist_ ,
Yes , Scriptrunner jira cloud validator uses only jira expressions ,
Can u please help me to write Jira expression to check assignee is from specified group or not.I am trying following code :
['groupname' : 'administrators'].includes[issue.assignee.accountId],
Please help me.above expression does not return true still assignee is from administrators
group.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cgade,
This is the same question that you raised on the question located here and I have answered your question on this post to not duplicate information.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomas Arguinzones ,
Welcome to the community. Please check this snippet and let me know if that helped.
import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def assignee = issue.getAssignee()
String groupName = "YourGroup"
if (assignee != null && groupManager.getUsersInGroup(groupName).contains(assignee)) {
//your code
}
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry , thank you for your reply...I havent tried it yet but is this for the cloud as I need it?
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomas Arguinzones ,
This should work for cloud, the main difference (I think) is you can't use a server side script.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ...thanks a lot for your assistance...unfortunately the sample code you sent only works for server and not for cloud...Kristian from scriptrunner tech support sent me a sample code that works great for the cloud...check it out when you get a chance. Thanks again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomas Arguinzones ,
Can you please share me the sample code for Jira Cloud,As I am very new to Jira Cloud.
How to check if Assignee is member of a group using scriptrunner for cloud
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tomas Arguinzones ,
Thank you very much for your prompt reply.I applied the same,now need to do changes in script console,can you please help me for below case.
My use case is,
I want validator to check assignee is from particular group ,can you please help me
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.