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

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

485 views 3 18
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