I built the script below in order to get value from the custom filed "sourceFieldName" then insert it to the custom filed "selectListFieldName" (Labels filed).
But unfortunately, it returns always null and the script is not able to return even the "sourceFieldName" value.
The script :
def issueKey = 'SS-43'
def issue = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
def fields = issue.fields as Map
// Specify the name of the select list field to set
def selectListFieldName = 'customfield_10131'
def sourceFieldName = 'customfield_10116'
//logger.info("${(selectListFieldName.value)}")
//logger.info("${(sourceFieldName.value)}")
// Get the Custom field to get the option value from
def customField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == selectListFieldName
} as Map
def customField2 = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == sourceFieldName
} as Map
//logger.info("customField${(customField)}")
\
def value3 = (fields[customField2] as String)?.value
logger.info("${(value3)}")
// logger.info("${(value4)}")
//def input1 = fields[customField2].value as String
// Check if the custom field returns a valid field and is not null
assert customField != null : "Cannot find custom field with name of: ${selectListFieldName}"
// Note: - Atlassian provide examples for the syntax to set other custom field types in the documentation page at https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples
def result = put("/rest/api/2/issue/${issueKey}")
// Uncomment the line below if you want to set a field which is not pressent on the screen. Note - If using this you must run the script as the ScriptRunner Add-On User.
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
(customField.id) : "${(value3)}"
]
])
.asString()
if (result.status == 204) {
return "The ${customField.name} select list field was successfully updated on the ${issueKey} issue"
} else {
return "${result.status}: ${result.body}"
}
Thank you Trudy
sourceFieldName is a Number filed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.