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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Set Customer Request Type during issue creation Groovy

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

1 vote
Answer accepted

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.

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.

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.

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
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

189 views 1 6
Read article

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