Hello,
i am creating an issue using the Java API in Groovy and am having trouble initilizing it with the custom field value for a certain custom field.
The custom field is numeric.
When you retrieve it via getCustomFieldValue you get a Double value.
When you look at the REST APIs json data for the issue it reads as
“customfield_13406”: “211355”,
But when using the issueManager to create an issue and want to set the field the field is always empty.
The field is in the create mask, when i create the issue via the Jira UI it can be populated.
So i think im using a wrong format when using the API like this:
Long containerLongId = <span>211354</span>L <span>// does not work</span>
<span>String</span> containerIdString = <span>"211354"</span> <span>// does not work</span>
issueInputParameters.addCustomFieldValue(containerLinkFieldId, containerKey)
Any ideas?
Thanks in Advance!
Full Source:
<span>import</span> com.atlassian.jira.bc.issue.IssueService
<span>import</span> com.atlassian.jira.issue.Issue
<span>import</span> com.atlassian.jira.issue.IssueInputParameters
<span>import</span> com.atlassian.jira.component.ComponentAccessor
<span>import</span> com.atlassian.jira.user.ApplicationUser
<span>import</span> com.atlassian.jira.util.ErrorCollection
<span>import</span> com.atlassian.jira.user.util.UserManager
<span>String</span> transitionUserKey = <span>"j.kisters"</span>
UserManager userManager = ComponentAccessor.getUserManager()
ApplicationUser runAsUser = userManager.getUserByName(transitionUserKey)
<span>// configure the issue to be created here</span>
<span>String</span> summary = <span>"My summary"</span>
Long projectId = <span>11400</span>L <span>// best put your project name here for readability</span>
<span>String</span> issueTypeId = <span>"3"</span> <span>// best put your issue type name here for readability</span>
<span>String</span> containerLinkFieldId = <span>"customfield_13406"</span>
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(projectId)
issueInputParameters.setIssueTypeId(issueTypeId)
issueInputParameters.setReporterId(transitionUserKey)
issueInputParameters.setSummary(summary)
<span>//TODO try out data type</span>
Long containerLongId = <span>211354</span>L <span>// does not work</span>
<span>String</span> containerIdString = <span>"211354"</span> <span>// does not work</span>
issueInputParameters.addCustomFieldValue(containerLinkFieldId, containerKey)
IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(runAsUser, issueInputParameters);
ErrorCollection createErrors = <span>null</span>
<span>if</span> (createValidationResult.isValid())
{
IssueService.IssueResult createResult = issueService.create(runAsUser, createValidationResult)
Issue issueCopy = createResult.getIssue()
<span>if</span> (issueCopy == <span>null</span>) {
log.error <span>'failed to create issue'</span>
} <span>else</span> {
log.error <span>'created issue '</span> + issueCopy.getKey()
}
} <span>else</span> {
log.error <span>'Create Result not valid'</span>
createErrors = createValidationResult.getErrorCollection()
<span>if</span> (createErrors != <span>null</span>) {
<span>for</span> (<span>String</span> error : createErrors ) {
log.error error
}
}
}