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.
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
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.