Set new summary on create by concuting String and custom field value (also string)

I would like to set a new summary for all issues created from service desk. Now the summary is set automatically from service desk, I've added a script on "create" transition to test:

import com.atlassian.jira.issue.Issue
 
Issue issue = issue;
 
issue.summary = "new user: ";

 

his work fine.

But I want to concut the text with a value from Custome field (which is mandatory for "Create" transition: that is a validation rule) .This time it won't work.

I've tried on few ways:

import com.atlassian.jira.issue.Issue 
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField 
import com.atlassian.jira.ComponentManager  
 
Issue issue = issue; 
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObjectByName("Name of the new user");
if(customField.getValue(issue) != null) {issue.summary = "new user: " + customField.getValue(issue);  
}else{
    issue.summary = "new user setup";
}

 

or with object id:

import com.atlassian.jira.issue.Issue 
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField 
import com.atlassian.jira.ComponentManager 
Issue issue = issue; 
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); 
CustomField customField = customFieldManager.getCustomFieldObject("customfield_10440");  
issue.summary = "new user: " + issue.getCustomFieldValue(customField);

 

Also I've tried with:

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.ComponentManager

Issue issue = issue;

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();

CustomField customField = customFieldManager.getCustomFieldObject(issue, "customfield_10440");

Object user = customField.getValueFromIssue(issue);

issue.summary = "New user: " + user ;

But nothing works fine.

Can you help me with that?

Thanks,

Kasia

 

1 answer

Hi Katarzyna,

Do you use JIRA 7 ? If yes then the componentManager is deprecated you should use ComponentAccessor instead

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Name of the new user'}

issue.summary = "new user " + issue.getCustomFieldValue(cf)

But I think in your case a behaviour would be better. Actually I updated the code above (just add the custom script post function as the first post function during the create transition)

 

Hi Thanos,

 

Thansk for reply,

We are using JIRA 6.3.1 and Script Runner: 3.0.10. Is this script ok, for this version?

Regards,

Kasia

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

170 views 0 4
Read article

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