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) {
			eventPublisher.register(this);    
		}
@EventListener
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);
println("first"+profieldsFieldValue);
logger.warn(profieldsFieldValue);
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)
if(profieldsFieldValue!=null){
	
Issue issue = issueEvent.getIssue();
	
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
customFieldAccountName.updateValue(null,issue,new ModifiedValue(customFieldAccountNameValue,profieldsFieldValue),changeHolder);

println("second"+customFieldAccountNameValue)
//logger.warn(customFieldAccountNameValue );
}
}
}

1 answer

1 accepted

0 votes
Accepted answer

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: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripting+Other+Plugins

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

320 views 0 1
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