Having trouble setting summary with combination of custom fields in post-function of create transition

I am trying to do the following: 

  • Hide summary from create screen (or at the very least have it prepopulated so users can ignore it - right now all I've been able to do is prepopulate it)
  • Once the ticket is created, populate summary with a combination of 3 custom fields that are required on the create screen ("Member ID": "Member First Name" + "Member Last Name") 

I have the following script set up on the create transition post-function (via Script Runner): 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
customField = customFieldManager.getCustomFieldObjectByName(“Member ID”)
customField1 = customFieldManager.getCustomFieldObjectByName(“Member First Name”)

customField2 = customFieldManager.getCustomFieldObjectByName(“Member Last Name”)
memberid = issue.getCustomFieldValue(customField)
memberfname = issue.getCustomFieldValue(customField1)

memberlname = issue.getCustomFieldValue(customField1)
Issue issue = issue;


issue.summary = memberid + “: “ + memberfname + " " + memberlname;

but no matter what I do I can't get it to work. It keeps just creating the issue with the default Summary that I put into the description of the Summary field on the particular field configuration in question. 

 

Anyone have suggestions on what I'm doing wrong/how I can get this to work? Your help would be much appreciated! Thanks! 

 

 

4 answers

This widget could not be displayed.

Hello. 

I am using this API in my groovy scripts to update issues in post functions. You also have to keep in mind that summary field should be present on edit issue screen for this to work.

p.s. don't forget to call post function after step "Creates the issue originally"

This widget could not be displayed.

Thanks Andrey, the summary field is present on the edit screen. I am new to Groovy and don't know how to incorporate the API you referenced - how would you go about writing what I'm trying to do? 

It will look like this: import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption if (issue != null) { org.apache.log4j.Category LOGGER = log; User curUser = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(); IssueService issueService = ComponentAccessor.getIssueService(); issueInputParameters = issueService.newIssueInputParameters(); issueInputParameters.setSummary("Your new summary"); IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(curUser, issue.getId(), issueInputParameters); if (updateValidationResult.isValid()) { IssueService.IssueResult updateResult = issueService.update(curUser, updateValidationResult, EventDispatchOption.DO_NOT_DISPATCH, false); if (updateResult.isValid()) { LOGGER.info("Updated issue " + String.valueOf(issue)); } else { LOGGER.error("Error validating updateResult"); Map<String, String> errors = updateResult.getErrorCollection().getErrors(); for (Map.Entry<String, String> entry : errors.entrySet()) { LOGGER.error(entry.getValue()); } } } else { LOGGER.error("Error validating updateValidationResult"); Map<String, String> errors = updateValidationResult.getErrorCollection().getErrors(); for (Map.Entry<String, String> entry : errors.entrySet()) { LOGGER.error(entry.getValue()); } } }

Since this is impossible to read...

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
if (issue != null) {
  org.apache.log4j.Category LOGGER = log;
  User curUser   ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();
  IssueService issueService = ComponentAccessor.getIssueService();
  issueInputParameters = issueService.newIssueInputParameters();
  issueInputParameters.setSummary("Your new summary");
  IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(curUser, issue.getId(), issueInputParameters);
if (updateValidationResult.isValid()) {
  IssueService.IssueResult updateResult = issueService.update(curUser, updateValidationResult, EventDispatchOption.DO_NOT_DISPATCH, false);
if (updateResult.isValid()) {
LOGGER.info("Updated issue " + String.valueOf(issue));
} else {
  LOGGER.error("Error validating updateResult");
  Map &lt; String, String &gt; errors = updateResult.getErrorCollection().getErrors();
  for (Map.Entry &lt; String, String &gt; entry: errors.entrySet()) {
    LOGGER.error(entry.getValue());
  }
}
} else {
  LOGGER.error("Error validating updateValidationResult");
  Map &lt; String, String &gt; errors = updateValidationResult.getErrorCollection().getErrors();
  for (Map.Entry &lt; String, String &gt; entry: errors.entrySet()) {
    LOGGER.error(entry.getValue());
  }
 }
}
This widget could not be displayed.

Hi Sara, my problem is quite similiar to your's - still coding and testing. https://answers.atlassian.com/questions/12266549/custom-script-runner-script---not-working-at-all

This widget could not be displayed.

-> answered.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

77 views 1 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you