Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set/update custom field value whenever an assignee is selected/changed using Groovy script?

Jay Karmarkar
Contributor
April 17, 2018

Hi,
I am trying to set the 'Team' custom field value whenever an assignee is selected or changed according to a csv file which has the mapping for the 'assignee - respective team'.
In the ScriptRunner, I'm setting up a custom listener for 'Issue Assigned' event and writing the following script to check the logic: if X is the assignee, set Y as the 'Team' custom field value.
I'm getting an error on the script console for "ResponsibleTeam_field.updateValue(..)" statement.
I'm new to this and any help would be really appreciated.

import org.apache.commons.csv.CSVRecord;
import org.apache.commons.csv.CSVFormat;
import java.nio.file.Paths;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.customfields.view.CustomFieldParams;
import com.atlassian.jira.issue.fields.config.FieldConfig;

Iterable<CSVRecord> reader = CSVFormat.RFC4180.withFirstRecordAsHeader().parse( new FileReader( "Path where the csv is stored" ) );
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
GroupManager groupManager = ComponentAccessor.getGroupManager();

def assigneeJira = Issue.getAssignee();
if (assigneeJira == 'null' || assigneeJira == null || assigneeJira==''){
assigneeJira ='';
}
String ResponsibleTeamJira = '';
CustomField ResponsibleTeam_field = customFieldManager.getCustomFieldObject('customfield_10120');
if (ResponsibleTeam_field){
ResponsibleTeamJira = Issue.getCustomFieldValue(ResponsibleTeam_field );
if (ResponsibleTeamJira == null){
ResponsibleTeamJira = '';
}
}
for (CSVRecord line : reader) {
String assigneeCsv = line.get("Assignee");
String ResponsibleTeamCsv= line.get("Responsible team");
if (assigneeJira.equals(assigneeCsv)
) {
Group Responsible_Team = groupManager.getGroup(ResponsibleTeamCsv);
List<Group> Responsible_Team_List = new ArrayList<Group>();
Responsible_Team_List.add(Responsible_Team);

def changeHolder = new DefaultIssueChangeHolder();
ResponsibleTeam_field.updateValue(null, Issue, new ModifiedValue(Issue.getCustomFieldValue(ResponsibleTeam_field), Responsible_Team_List ),changeHolder);
}

}

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2018

What is the error?

Jay Karmarkar
Contributor
April 18, 2018

Hi Alexey,

This is the exact error that I'm getting:

[Static type checking] Cannot find matching method
com.atlassian.jira.issues.fields.CustomField#updateValue(<unknown parameter type>,
java.lang.Class <com.atlassian.jira.issue.Issue>,com.atlassian.jira.issue.ModifiedValue, com.atlassian.jira.issue.util.DefaultIssueChangeHolder). Please check if the declared type is right and if the method exists.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 18, 2018

It is a static compilation error. Try to execute the code.

Jay Karmarkar
Contributor
April 19, 2018

I tried changing the assignee but it did not work as expected.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 19, 2018

What was the error?

Suggest an answer

Log in or Sign up to answer