Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set a customfield to a number does not work when creating issue in groovy

Jens Kisters __SeibertSolutions
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2020

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 = 211354L // does not work
String containerIdString = "211354" // does not work
issueInputParameters.addCustomFieldValue(containerLinkFieldId, containerKey)

Any ideas?
Thanks in Advance!

Full Source:

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.user.util.UserManager

String transitionUserKey = "j.kisters"

UserManager userManager = ComponentAccessor.getUserManager()
ApplicationUser runAsUser = userManager.getUserByName(transitionUserKey)

// configure the issue to be created here
String summary = "My summary"
Long projectId = 11400L // best put your project name here for readability
String issueTypeId = "3" // best put your issue type name here for readability
String containerLinkFieldId = "customfield_13406"

IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(projectId)
issueInputParameters.setIssueTypeId(issueTypeId)
issueInputParameters.setReporterId(transitionUserKey)
issueInputParameters.setSummary(summary)

//TODO try out data type
Long containerLongId = 211354L // does not work
String containerIdString = "211354" // does not work
issueInputParameters.addCustomFieldValue(containerLinkFieldId, containerKey)

IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(runAsUser, issueInputParameters);

ErrorCollection createErrors = null
if (createValidationResult.isValid())
{
	IssueService.IssueResult createResult = issueService.create(runAsUser, createValidationResult)

	Issue issueCopy = createResult.getIssue()
	if (issueCopy == null) {
		log.error 'failed to create issue'
	} else {
		log.error 'created issue ' + issueCopy.getKey()
	}
} else {
	log.error 'Create Result not valid'
	createErrors = createValidationResult.getErrorCollection()
	if (createErrors != null) {
		for (String error : createErrors ) {
			log.error error
		}
	}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer