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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

85 views 0 5
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