Hi all,
I am using a groovy script in a REST endpoint, and I'd like to use the custom field to get value.
I have this block of values
def value = [
"a9d43495-9bb2-cdb0-99ea": value1,
"09fb242c-d6f2-a4a0-fea3": value2,
"60dd5447-a7c0-68fd-fb68": value3
]
and I have a custom field with id customfield_11601, any idea about how can I define it?
I tried this:
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11601")
def cFieldValue = issue.getCustomFieldValue(cField)
def value = [
"a9d43495-9bb2-cdb0-99ea": value1,
"09fb242c-d6f2-a4a0-fea3": value2,
"60dd5447-a7c0-68fd-fb68": cFieldValue
]
but it did not work. Any help will be much appreciated.
Thanks
Hello,
The script is correct. Where are you using this script, on Script Console? Because if that's the case, you are not defining the issue to get the custom field. Also what errors are you getting?
When I test this script like this, it works:
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("DSP-2")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11802")
def cFieldValue = issue.getCustomFieldValue(cField)
def value = [
"a9d43495-9bb2-cdb0-99ea": "value1",
"09fb242c-d6f2-a4a0-fea3": "value2",
"60dd5447-a7c0-68fd-fb68": cFieldValue
]
return value
Regards.
Hi,
thanks for the reply.
I have created a Jira template with a few custom fields, and with ScriptRunner I have imported a groovy script as REST endpoints
And I have my key button
You are correct, I am not defining any issue, but which one should I define?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, got it, if I do
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("INF-30")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11601")
def cFieldValue = issue.getCustomFieldValue(cField)
It works, but def issue value "INF-30" is static, how can I make it progressive for the new issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You'll need to pass the issue key in your web item link then parse that out in your rest api.
In web item link, try /rest/scriptrunner/latest/custom/DEPLOY?key=$issue.key
Then in your DEPLOY rest API
def issueKey = queryParams.getFirst('key')
def issue = issueManager.getIssueObject(issueKey)
Maybe add a bit of error trapping:
if(!issueKey){
return Response.serverError().entiy([error: "You must provide a key parameter"]).build()
}
if(!issue){
return Response.serverError().entiy([error: "The key provided [$issueKey] is not a valid Jira issue."]).build()
}
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.
Repeating as a separate answer ... in case you'd like to mark this as the correct answer:
You'll need to pass the issue key in your web item link then parse that out in your rest api.
In web item link, try /rest/scriptrunner/latest/custom/DEPLOY?key=$issue.key
Then in your DEPLOY rest API
def issueKey = queryParams.getFirst('key')
def issue = issueManager.getIssueObject(issueKey)
Maybe add a bit of error trapping:
if(!issueKey){
return Response.serverError().entiy([error: "You must provide a key parameter"]).build()
}
if(!issue){
return Response.serverError().entiy([error: "The key provided [$issueKey] is not a valid Jira issue."]).build()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter, thanks for the reply
I've configured
web item link, try /rest/scriptrunner/latest/custom/DEPLOY?key=$issue.key
and
def issueKey = queryParams.getFirst('key')
def issue = issueManager.getIssueObject(issueKey)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11601")
def cFieldValue = issue.getCustomFieldValue(cField)
but no luck, getting the same null value, do you know how to debug it?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Make sure your endpoint definition includes the queryParams in the call
DEPLOY(
httpMethod: "POST",
groups: ["jira-administrators","jira-users"]
) {MultivaluedMap queryParams, String body ->
def issueKey = queryParams.getFirst('key')
def issue = issueManager.getIssueObject(issueKey)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11601")
def cFieldValue = issue.getCustomFieldValue(cField)
/.../
}
And then dump some values to the log ...
/.../
log.info "queryParams = $queryParams"
def issueKey = queryParams.getFirst('key')
log.issueKey "issueKey = $issueKey"
def issue = issueManager.getIssueObject(issueKey)
log.issueKey "issue = $issue"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11601")
def cFieldValue = issue.getCustomFieldValue(cField)
Which of the log outputs are visible in [jira-home]/log/atlassian-jira.log should give you some hints as to what's happening.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I did not get you. This is what I have, I mean part of the code
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("INF-39")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cFieldStackName = customFieldManager.getCustomFieldObject("customfield_11601")
def cFieldValueStackName = issue.getCustomFieldValue(cFieldStackName)
def cFieldVpcRange = customFieldManager.getCustomFieldObject("customfield_11602")
def cFieldValueVpcRange = issue.getCustomFieldValue(cFieldVpcRange)
def cFieldSubRange = customFieldManager.getCustomFieldObject("customfield_11603")
def cFieldValueSubRange = issue.getCustomFieldValue(cFieldSubRange)
def value = [
"a9d43495-9bb2-cdb0-99ea-066c0cc54c34": cFieldValueVpcRange,
"09fb242c-d6f2-a4a0-fea3-64b5641f8023": cFieldValueSubRange,
"60dd5447-a7c0-68fd-fb68-65aeb4025d37": cFieldValueStackName
]
def jsonBody = [:]
jsonBody.put("FormValues", value)
jsonBody.put("ProjectID", ProjectName )
jsonBody.put("EnvironmentId", "Environments-1")
jsonBody.put("ReleaseID", newReleaseId)
def bodyjson = JsonOutput.prettyPrint(JsonOutput.toJson(jsonBody))
def newDeployPath = "deployments"
def newDeploy = new HTTPBuilder(URL)
newDeploy.request(POST) { req ->
uri.path = newDeployPath
requestContentType = ContentType.JSON
headers.'X-Octopus-ApiKey' = 'API-xxx'
body = bodyjson
response.success = { resp, JSON ->
return JSON
}
response.failure = { resp ->
return "Request failed with status ${resp.status}"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
2019-08-22 08:27:51,329 https-jsse-nio-443-exec-21 WARN carmine.fabrizio 507x7841x1 1qaetpz 10.100.3.55 /rest/scriptrunner/latest/custom/customadmin/com.onresolve.scriptrunner.canned.common.rest.CustomRestEndpoint [c.o.scriptrunner.runner.RestEndpointManagerImpl] Execution of REST endpoint script failed
groovy.lang.MissingPropertyException: No such property: queryParams for class: Script25
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What does your rest endpoint declaration line look like?
Seems like you've cut that out of the code you shared.
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.