This code works fine in projects A and B of Jira:
import groovy.json.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseException
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import org.apache.log4j.Logger
def log = Logger.getLogger("com.acme.CreateSubtask")
def issue = ComponentAccessor.getIssueManager().getIssueObject("TS-74")
log.info('Current issue is: ' + issue)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def newParentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(0000L) // <- here is ID custom field what u have to update.
def jsonObj = new JsonSlurper().parseText('{ "fields": { "customfield_10976": "GP-259"} }') //customfield_23280 is Parent Link ID
def parentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10976L) // <- id parent link custom field
def userName = "user"
def password = "password"
def fullAddress = "https://onetwo.com/rest/api/2/issue/${issue.key}"
def authString = "${userName}:${password}".getBytes().encodeBase64().toString()
log.info(fullAddress);
log.info("parentLink ${parentLink}")
def client = new RESTClient(fullAddress)
try{
//necessary to overwrite the value of custom field, via rest only update if custom field have value null.
parentLink.updateValue(null, issue, new ModifiedValue(
issue.getCustomFieldValue(parentLink), null),
new DefaultIssueChangeHolder())
client.put(path: fullAddress,
contentType: groovyx.net.http.ContentType.JSON,
body: jsonObj,
headers: [Accept: 'application/json',
Authorization: "Basic ${authString}"]
)
} catch (final HttpResponseException e) {
log.warn e
}
However, the above code DOES not work in other projects, e.g. 'C' and 'D'. What settings of Jira should be turned on? Thanks in advance?
No exceptions are thrown. Just empty exception.