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

0 vote

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
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 4 hours ago 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...

26 views 0 2
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