Skip to main content
Book your demo
Example scripts
To homepage
Jira
Cloud icon
Cloud

Manage Entity Properties

Created 1 year ago, Updated 7 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
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. Work Item Example
def issueEntity = WorkItems.getByKey("WORK_ITEM_KEY").getEntityProperties()

// Setting Json, boolean and datetime properties on work item's entity (issueEntity)
issueEntity.setJson("workItemTestKey", JsonOutput.toJson([name: "WorkItemTest", value: "TestWorkItemValue"]))
issueEntity.setBoolean("workItemTestBool", true)
issueEntity.setLocalDateTime("workItemTestLocalDateTime", LocalDateTime.now())

// Getting issue property values
issueEntity.getJson("workItemTestKey")
issueEntity.getBoolean("workItemTestBool")
issueEntity.getLocalDateTime("workItemTestLocalDateTime")

// Getting issue entity property
issueEntity.getEntityProperty("workItemTestBool")

// All issue keys
issueEntity.getKeys()

// Deleting all issue properties
issueEntity.delete("workItemTestKey")
issueEntity.delete("workItemTestBool")
issueEntity.delete("workItemTestLocalDateTime")

// 3. Space Example
def projectEntity = Spaces.getByKey("SPACE_KEY").getEntityProperties()

// Setting properties on space (project)
projectEntity.setInteger("spaceTestKey", 200)

// Getting project property values
projectEntity.getJson("spaceTestKey")
projectEntity.getEntityProperty("spaceTestKey")
projectEntity.getKeys()

// Deleting project property
projectEntity.delete("spaceTestKey")

// 4. Comment Example
def workItem = WorkItems.getByKey("WORK_ITEM_KEY")
def firstComment = workItem.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