The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

ScriptRunner Cloud - Fast Track Condition: User in group

Artem Chaplygin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 3, 2023

Hi! I'm trying to make simple condition for fast track post-function. 

I knew how to make it for Data Center, but can't figure it out for cloud service. 

 

I found condition example from ScriptRunner Cloud manual: 

user.groups.includes('its-test')

 

But it's not working, can't access users: "No such property: user for class: Script1 on line 1". Don't know how to import user's groups for this condition.
Can anyone help me write correct condition or maybe advise some good manuals for scriptrunner and jira rest api. 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Artem Chaplygin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 5, 2023

AI helps me, here is a working code for me:

import org.slf4j.Logger
import org.slf4j.LoggerFactory

def logger = LoggerFactory.getLogger("com.example.script")
def reporter = issue.fields.reporter
def accountId = reporter?.accountId
def response = get("/rest/api/2/user/groups?accountId=${accountId}").asJson()
logger.error("Response status: ${response.getStatus()}")
logger.error("AccountId: $accountId")
logger.error("Response: ${response.rawBody}")

if (response.rawBody) {
def groups = new groovy.json.JsonSlurper().parseText(response.getBody().toString())
def isInItsTestGroup = groups.find { it.name == 'CHANGE_THIS_GROUPNAME' } != null
logger.error("Groups: $groups")
logger.error("IsInItsTestGroup: $isInItsTestGroup")
isInItsTestGroup
} else {
false
}

 You can skip all logger lines if you don't need them. 

Don't forget to change the name of your group CHANGE_THIS_GROUPNAME

TAGS
AUG Leaders

Atlassian Community Events