Need to update a custom field value

We have a business requirement where we have to update a custom field with the value of a profield when the issue is being created. For this we have applied a post function script which runs on create issue transition in the workflow. But the script startup failed and unable to resolve classes error is coming in the logs.

In the script profield data is coming correctly.  

Can you please suggest the solution to resolve the issue and any modification if required.

This is the error log file 

import com.atlassian.jira.component.ComponentAccessor
import com.deiser.jira.profields.api.field.FieldService
import org.apache.log4j.Logger
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.Issue
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
public class UpdateStudioJobsListener {
//Register the Event Listener Class with the EventPublisher         		 
		 public UpdateStudioJobsListener(EventPublisher eventPublisher) {
public void onIssueEvent(IssueEvent issueEvent) {
def FIELD_ID = 7;
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class);
def logger = Logger.getLogger(getClass());
def profieldsField = fieldService.get(FIELD_ID);
def profieldsFieldValue = profieldsField.getValueInProject(issue.projectObject);
def ComponentManager componentManager = ComponentManager.getInstance();
def customFieldManager = ComponentManager.getCustomFieldManager();
def customFieldAccountName= customFieldManager.getCustomFieldObject('customfield_21900');          //write your own custom field id here
def customFieldAccountNameValue = issue.getCustomFieldValue(customFieldAccountName);
println("first second"+customFieldAccountNameValue)
Issue issue = issueEvent.getIssue();
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
customFieldAccountName.updateValue(null,issue,new ModifiedValue(customFieldAccountNameValue,profieldsFieldValue),changeHolder);

//logger.warn(customFieldAccountNameValue );

1 answer

1 accepted

You have a bunch of missing imports, eg ModifiedValue

And, this is not going to work:

import com.deiser.jira.profields.api.field.FieldService

You need to use @WithPlugin annotation to allow the script to access the classloader of the profields plugin. 

See this page:

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

431 views 8 26
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