Example scripts
To homepage
Jira

Manage Entity Properties
Features
Script consoleCreated 3 month(s) ago, Updated 1 day(s) ago
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira
Language |
groovy
import groovy.json.JsonOutput
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
// 1. User Example
def userEntity = Users.getByAccountId("userAccountID").getEntityProperties()
// Setting Json, string, date properties on user
userEntity.setJson("userTestKey", JsonOutput.toJson([name: "Test", value: "TestValue"]))
userEntity.setLocalDate("userTestingDate", LocalDate.now())
userEntity.setString("userTestString", "Hello World")
// Getting user property values
userEntity.getJson("userTestKey")
userEntity.getLocalDate("userTestingDate")
userEntity.getString("userTestString")
// Getting user json entity property
userEntity.getEntityProperty("userTestKey")
// All user keys
userEntity.getKeys()
// Deleting all user properties
userEntity.delete("userTestKey")
userEntity.delete("userTestingDate")
userEntity.delete("userTestString")
// 2. Issue Example
def issueEntity = Issues.getByKey("ISSUE_KEY").getEntityProperties()
// Setting Json, boolean and datetime properties on issue
issueEntity.setJson("issueTestKey", JsonOutput.toJson([name: "IssueTest", value: "TestIssueValue"]))
issueEntity.setBoolean("issueTestBool", true)
issueEntity.setLocalDateTime("issueTestLocalDateTime", LocalDateTime.now())
// Getting issue property values
issueEntity.getJson("issueTestKey")
issueEntity.getBoolean("issueTestBool")
issueEntity.getLocalDateTime("issueTestLocalDateTime")
// Getting issue entity property
issueEntity.getEntityProperty("issueTestBool")
// All issue keys
issueEntity.getKeys()
// Deleting all issue properties
issueEntity.delete("issueTestKey")
issueEntity.delete("issueTestBool")
issueEntity.delete("issueTestLocalDateTime")
// 3. Project Example
def projectEntity = Projects.getByKey("PROJECT_KEY").getEntityProperties()
// Setting properties on project
projectEntity.setInteger("projectTestKey", 200)
// Getting issue property values
projectEntity.getJson("projectTestKey")
projectEntity.getEntityProperty("projectTestKey")
projectEntity.getKeys()
// Deleting project property
projectEntity.delete("projectTestKey")
// 4. Comment Example
def issue = Issues.getByKey("ISSUE_KEY")
def firstComment = issue.getComments().getAt(0)
def commentEntity = firstComment.getEntityProperties()
// Setting property on comment
commentEntity.setAsActualType('testingInstance', Instant.now())
// Getting comment property value
commentEntity.getAsActualType("testingInstance", Instant)
commentEntity.getEntityProperty("testingInstance")
// All comment keys
commentEntity.getKeys()
// Deleting comment property
commentEntity.delete("testingInstance")
Having an issue with this script?
Report it here