Folks,
I'm trying to set a custom field based on the link type. I'm able to set the linked key through listener. However, I'm unable to clear it when the link is removed. Below is the code snippet. Please assist.
if (it.type.inward == 'is a defect of'){
logger.info("Inward is a defect of links: "+ it.inwardIssue.key)
def result = put("/rest/api/3/issue/${issue.key}") .header('Content-Type', 'application/json')
.body([
fields: [ customfield_14268:it.inwardIssue.key ] ]) .asString()
}else if(it.type.inward == null){
def result = put("/rest/api/3/issue/${issue.key}") .header('Content-Type', 'application/json') .body([ fields: [ customfield_14281: '' ] ]) .asString()
}
Hi Vimalraj,
For your requirement you can use an approach similar to what is provided in this Adaptavist code snippet.
I've modified the code snippet above slightly to the working sample below:-
def projectKey = 'MOCK'
def issueType = get('/rest/api/2/issuetype').asObject(List).body.find { it['name'] in ['Story','Task'] }['name']
def customFields = get("/rest/api/2/field").asObject(List).body.findAll { (it as Map).custom } as List<Map>
def sampleList = customFields.find { it.id == 'customfield_12818' }?.id
if (issueType in ['Story', 'Task']) {
put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields: [
(sampleList):null
]
]).asString()
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.