Hello guys,
I am trying to create an issue by post-function using ScriptRunner. This is a piece of my code:
if (createValidationResult.isValid())
{
log.error("i am in createValidationResult")
log.error("will be created")
IssueResult createResult = issueService.create(
user, createValidationResult)
Issue createdIssue = createResult.getIssue()
IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getIssueLinkManager()
IssueLinkType linkType = issueLinkTypeManager.getIssueLinkType(new Long(10303))
issueLinkTypeManager.createIssueLinkType(createdIssue.getId(), issue.id, linkType.getId(), null, user)
log.error("created ")
log.error("DESCRIPTION OF CREATED ISSUE: " + createResult.getIssue().getDescription())
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}
The issue is create but without any custom fields. All methods after issueService.create, like "createResult or log.error" is not executed.
Any suggestions? What is wrong on my code?
Best Regards.
Hello @luanlopes94
How exactly you create issue? Can you provide code
For example:
def projectid = ComponentAccessor.getProjectManager().getProjectByCurrentKey("DS").getId()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(projectid)
.setIssueTypeId("10107")
.setSummary("This is a summary")
.setReporterId(user.key)
.setAssigneeId(user.key)
.setDescription("I am a description")
.setStatusId("1")
.setPriorityId("2")
log.error("Input params: {}", issueInputParameters)
IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters);
log.error("Validation?: {}", createValidationResult.isValid().toString())
if (createValidationResult.isValid())
{
IssueService.IssueResult createResult = issueService.create(user, createValidationResult);
log.error("Creation result?: {}", createResult.isValid().toString())
if (!createResult.isValid())
{
log.error("Something went wrong")
}
}
Hello Mark,
Sorry for my late reply. There is my code:
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( sum )
.setDescription("test desc")
.setIssueTypeId(issueTypeID)
.setPriorityId(issue.priorityId)
.setReporterId(issue.reporterId)
.setAssigneeId(issue.assigneeId)
log.error("issueInputParameters: " + issueInputParameters.getSummary())
log.error("getCustomField do issueInputParam: " + issueInputParameters.getCustomFieldValue("customfield_10301"))
ApplicationUser user = (ApplicationUser) ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CreateValidationResult createValidationResult =
issueService.validateCreate(user, issueInputParameters)
issueInputParameters.setSkipScreenCheck(true)
log.error("issue input parameters: " + issueInputParameters.getCustomFieldValue("customfield_10301"))
log.error("User: " + ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
log.error(createValidationResult.getErrorCollection())
log.error("Validation?: " + createValidationResult.isValid().toString())
if (createValidationResult.isValid())
{
log.error("i am in createValidationResult")
log.error("will be created")
IssueResult createResult = issueService.create(
user, createValidationResult)
log.error("Creation result?: {}", createResult.isValid().toString())
log.error("created ")
log.error("DESCRIPTION OF CREATED ISSUE: " + createResult.getIssue().getDescription())
if (!createResult.isValid())
{
log.error("Error while creating the issue.")
}
}
else
{
String cause = StringUtils.join(createValidationResult.getErrorCollection().getErrorMessages(), "/")
log.error("cause :" + cause)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where did you set customfield value in issueinputparameters?
It should be like this
issueInputParameters.setProjectId(projectid)
.setIssueTypeId("10107")
.setSummary("This is a summary")
.setReporterId(user.key)
.setAssigneeId(user.key)
.setDescription("I am a description")
.setStatusId("1")
.setPriorityId("2")
.addCustomFieldValue("customfiled_10111", "test")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used this:
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( sum )
.setDescription("test desc")
.setIssueTypeId(issueTypeID)
.setPriorityId(issue.priorityId)
.setReporterId(issue.reporterId)
.setAssigneeId(issue.assigneeId)
.addCustomFieldValue( cf_ModelName_field, cf_ModelName.toString())
.addCustomFieldValue( cf_ReleaseType_field, cf_ReleaseType.toString())
.addCustomFieldValue( cf_ModelCategory_field, cf_ModelCategory.toString())
.addCustomFieldValue( cf_Organization_field, cf_Organization)
.addCustomFieldValue( cf_SIMCard_field, cf_SIMCard)
And for the custom fields values I used it:
/** Model Name - customfield_10301 **/
String cf_ModelName = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10301"))
Long cf_ModelName_field = 10301L
log.error("cf_ModelName: " + cf_ModelName)
...
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.