Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Create Issue with Insight customfield filled

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

 

 

1 answer

0 votes
Hana Kučerová Community Leader Jan 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.

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you