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

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

Suggest an answer

Log in or Sign up to answer
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