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

Set Customer Request Type during issue creation Groovy

Mariusz Piotrowski July 17, 2020

Hi,

I saw few threads about this topic, but all were related to old Customer Request Type values e.g. it/request-type. In JIRA 7.11 I have new values e.g. project/UUID. I'm trying to create issues with groovy (Insight if that makes a difference). My code looks something like this:

IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "Odebranie uprawnień" )
.setIssueTypeId(issue.issueTypeId)
.setPriorityId(issue.priority.id)
.setReporterId(issue.reporterId)
.addCustomFieldValue("customfield_10802", "isd/bba760da-e62d-4da3-b719-d688beecc9ac")

I have also tried:
1. SD Automation - fires too late for my other post functions

2. Power Scripts - can set CRT in later transitions, but on Create throws error with key not existing (probably launches before link creation).

3. Same script in Script Runner also doesn't set CRT

2 answers

1 accepted

2 votes
Answer accepted
Mariusz Piotrowski August 6, 2020

I have found a reason. Script Runner (customer has version 5.4.12 and JIRA 7.11.2) doesn't set custom fields which are not on a Create screen. issueManager.updateIssue is not needed in this case. Probably post function Creates issue originally does the job.

0 votes
Jean-Philippe Comeau July 27, 2020

Is this the full code snippet?

The CustomField may have the right value but you need to update the issue.  I use IssueManager for that

issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)

 You can get the issue by grabbing the newly created issue as a return from the creation.

Mariusz Piotrowski August 4, 2020

Sorry for late reply, I was on a vacation.

Here is some longer excerpt:

IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "Odebranie uprawnień" )
.setIssueTypeId(issue.issueTypeId)
.setPriorityId(issue.priority.id)
.setReporterId(issue.reporterId)
.addCustomFieldValue("customfield_15732", it.getObjectKey())
.addCustomFieldValue("customfield_11901", stanowiskoValue)
.addCustomFieldValue("customfield_12100", jednostkaOrgValue as String)
.addCustomFieldValue("customfield_11304", nazwaKomOrgValue)
.addCustomFieldValue("customfield_15503", uzasadnienieValue)
.addCustomFieldValue("customfield_15245", zgloszenieDlaValue)
.addCustomFieldValue("customfield_10802", "isd/bba760da-e62d-4da3-b719-d688beecc9ac")

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters)
if (createValidationResult.isValid())
{
IssueService.IssueResult createResult = issueService.create(user, createValidationResult)
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), createResult.issue, EventDispatchOption.ISSUE_UPDATED, false)
}

I'm creating tasks in a loop. Other custom fields are being set. I have added updateIssue, but it didn't help. There are no errors in logs.

Mariusz Piotrowski August 4, 2020

Sorry for late reply, I was on a vacation.

Here is a longer excerpt from my script:

 IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters
.setProjectId( issue.getProjectObject().getId() )
.setSummary( "Odebranie uprawnień" )
.setIssueTypeId(issue.issueTypeId)
.setPriorityId(issue.priority.id)
.setReporterId(issue.reporterId)
.addCustomFieldValue("customfield_15732", it.getObjectKey())
.addCustomFieldValue("customfield_11901", stanowiskoValue)
.addCustomFieldValue("customfield_12100", jednostkaOrgValue as String)
.addCustomFieldValue("customfield_11304", nazwaKomOrgValue)
.addCustomFieldValue("customfield_15503", uzasadnienieValue)
.addCustomFieldValue("customfield_15245", zgloszenieDlaValue)
.addCustomFieldValue("customfield_10802", "isd/bba760da-e62d-4da3-b719-d688beecc9ac")

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters)
//log.warn "Mario przed createValidationResult"
if (createValidationResult.isValid())
{
//log.warn("Mario tworzenie zgłoszeń OK")
IssueService.IssueResult createResult = issueService.create(user, createValidationResult)
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), createResult.issue, EventDispatchOption.ISSUE_UPDATED, false)
}

I'm creating tasks in a loop. I have added updateIssue as you suggested, but it didn't help. There are no errors in logs. Other custom fields are being set.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events