Create Issue with Insight customfield filled

Christof Hurst January 14, 2021

Hi community,

I want to create issues via groovy and want to set an Insight customfield. But I didn't get the correct syntax. Neither with object, objectId or objectKey I'm able to fill the field.

Did anybody have tips?

import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.component.ComponentAccessor

String[] putObject = [objectBean]
//String[] putObject = [objectBean.id]
//String[] putObject = [objectBean.objectKey]

Long cfId = 12345L
Long projectId = 11111L
String issueTypeId = "22222"
String summary = "TestSummary"
def reporter = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def issueService = ComponentAccessor.issueService

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters
.setProjectId(projectId)
.setIssueTypeId(issueTypeId)
.setSummary(summary)
.setReporterId(reporter.name)

issueInputParameters.addCustomFieldValue(cfId, putObject)

CreateValidationResult createValidationResult = issueService.validateCreate(reporter, issueInputParameters)

if (createValidationResult?.isValid()) {
IssueResult createResult = issueService.create(reporter, createValidationResult)

if (!createResult.isValid()) {
return null
} else {
return createResult.issue
}
}
return null

 

 

2 answers

0 votes
Christof Hurst February 1, 2022

I think it is the field dependencies to other insight fields. If they are not filled in the correct order, then the value (or id) is discarded.

0 votes
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 14, 2021

Hi @Christof Hurst ,

welcome to the Atlassian Community!

It seems to me the problem could be in the variable putObject.

When you want to store insight objects, the variable needs to be 

List<ObjectBean>

i.e list of objects.

Where do you have this script? How do you obtain "objectBean"?

Thank you.

Christof Hurst June 24, 2021

Hi,

the objectBean is fetched from various places. It's a general problem. But it's always the same class. In most cases it works with [objectBean.objectKey]. Maybe sometimes it fails because the customfield configuration depends on former fields to be set. 

Nevertheless it works when setting the fields after creation via 

createdIssue.setCustomFieldValue(cf,[objectBean])

In that case the objectBean was retrieved by

def objectBean = issue.getCustomFieldValue(cf)[0]

Suggest an answer

Log in or Sign up to answer