Hello Team,
Can some body help on how to do a null check in Jira cloud while using Script runner for Jira cloud on Listener. Also would like to validate if the issue type is CII.
- Issue Link Created Event
- Few fields has to be copied from parent to child when a issue is linked as duplicate
The problem is history is being updated separately for different put requests, is their way we can make it as one update. I am a beginner, however can't make it as one due to null check and need to set up destination value as well to null.
{noformat}// Check if the type of the issue link type of the issue is 'duplicate'
if (issueLink.issueLinkType.name == "Duplicate"){
def destinationIssueResponse = get("/rest/api/2/issue/${issueLink.destinationIssueId}").asObject(Map)
def destinationIssueKey = destinationIssueResponse.body.key
logger.info("Child Jira ticket: ${destinationIssueKey}")
def sourceIssueResponse = get("/rest/api/2/issue/${issueLink.sourceIssueId}").asObject(Map)
def sourceIssueKey = sourceIssueResponse.body.key
logger.info("Parent Jira ticket: ${sourceIssueKey}")
def parentcii = get('/rest/api/2/issue/' + destinationIssueKey)
.header('Content-Type', 'application/json')
.asObject(Map)
.body
def parentpriority = parentcii.fields.priority.name
logger.info("Priority field value: ${parentpriority} of parentcii")
def parentissuekey = parentcii.key
logger.info("Jira id: ${parentissuekey} of parentcii")
def parentissuestatus = parentcii.fields.status.name
logger.info("Issue status: ${parentissuestatus} of parentcii")
def parentissuetype = parentcii.fields.issuetype.name
logger.info("Issue type: ${parentissuetype} of parentcii")
//assignee
if (parentcii.fields.assignee != null){
def parentissueassignee = parentcii.fields.assignee.accountId
logger.info("Assignee is : ${parentissueassignee} of parentcii")
def childassignee = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
assignee:[id:parentissueassignee]
]
])
.asString()
} else {
def childassignee = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
assignee: null
]
])
.asString()
}
//Duplicate JIRA ETA & Code Drop ID – Planned
if (parentcii.fields.customfield_11961 != null){
def CodeDropIDPlanned = parentcii.fields.customfield_11961.value
logger.info("Code Drop ID - Planned: ${CodeDropIDPlanned} of parentcii")
def dupETAupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_12130:CodeDropIDPlanned,
customfield_11961:[value:CodeDropIDPlanned]
]
])
.asString()
} else {
def dupETAupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_12130: null,
customfield_11961: null
]
])
.asString()
}
//Defect Category
if (parentcii.fields.customfield_11200 != null){
def DefectCategory = parentcii.fields.customfield_11200.value
logger.info("Defect Category: ${DefectCategory} of parentcii")
def Estdateupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11200:[value:DefectCategory]
]
])
.asString()
} else {
def Estdateupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11200: null
]
])
.asString()
}
//Estimated Close Date
if (parentcii.fields.customfield_11402 != null){
def EstimatedCloseDate = parentcii.fields.customfield_11402.value
logger.info("Estimated Close Date: ${EstimatedCloseDate} of parentcii")
def Estdateupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11402:EstimatedCloseDate
]
])
.asString()
} else {
def Estdateupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11402: null
]
])
.asString()
}
//Initiating Dept
if (parentcii.fields.customfield_11403 != null){
def InitiatingDept = parentcii.fields.customfield_11403.value
logger.info("Initiating Dept: ${InitiatingDept} of parentcii")
def deptupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11403:[value:InitiatingDept]
]
])
.asString()
} else {
def deptupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11403: null
]
])
.asString()
}
//Lifecycle
if (parentcii.fields.customfield_11903 != null){
def Lifecycle = parentcii.fields.customfield_11903.value
logger.info("Lifecycle: ${Lifecycle} of parentcii")
def Lifecycleupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11903:[value:Lifecycle]
]
])
.asString()
} else {
def Lifecycleupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
customfield_11903: null
]
])
.asString()
}
def childciiupdate = put('/rest/api/2/issue/' + sourceIssueKey)
.header('Content-Type', 'application/json')
.body([
fields: [
priority:[name:parentpriority],
customfield_12128:parentissuekey,
customfield_12129:parentissuestatus,
customfield_12133:parentissuetype
]
])
.asString()
}
{noformat}