How can i get Custom field values of workflow using groovy?

How can i get the custom field value in jira using groovy on my terminal under log file.

3 answers

1 accepted

This widget could not be displayed.

If i got it right, you want to get the value of a custom field in jira logs, when a workflow is executed.

If so, use a groovyscript in your post function like the following:

import com.atlassian.jira.ComponentManager;
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; 


CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
 
CustomField customField_name = customFieldManager.getCustomFieldObjectByName( "customfield_name" );


log.warn ("value: "+ issue.getCustomFieldValue( customField_name))

Test it first.

Cheers

Thanks kostas, Thats what i exactly wanted. can i perform transition associated with this custom fieldd?

What do you mean by "can i perform transition associated with this custom field?"

You just have to create a file and use it in a scripted post function of your workflow.

Have a look at jamie's plugin page and you will clarify most of things.

I tried to use above code, but seems 

ComponentManager.getInstance().getCustomFieldManager(); decrecated. 

How can I get single line customer value using JIRA 7.1.2 API?

Thanks!

I tried to use above code, but seems 

ComponentManager.getInstance().getCustomFieldManager(); decrecated. 

How can I get single line customer value using JIRA 7.1.2 API?

Thanks!

Use:

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.getCustomFieldManager()

I did have following lines in my post:

 

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def firstnameTypeCF = customFieldManager.getCustomFieldObject("First Name")
def firstnameFieldV = parentIssue.getCustomFieldValue(firstnameTypeCF)

But failed with following error:

2016-09-12 13:06:51,034 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2016-09-12 13:06:51,041 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: TPSHR-1372, actionId: 1, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$1.call(Unknown Source)
	at Script58.run(Script58.groovy:71)

 

I don't know why it's failed?

Thanks!

 

 

The CustomFieldManager.getCustomFieldObject method signature takes a custom field ID (either a Long or a string that has the numeric ID). You want the ...ByName signature that Kostas used. Otherwise, the custom field manager will probably return null, and you'll get that null pointer exception.

import com.atlassian.jira.component.ComponentAccessor;

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def firstName = customFieldManager.getCustomFieldObjectByName("First Name");
def firstnameFieldV = parentIssue.getCustomFieldValue(firstName)

I'm also assuming that the parentIssue variable is defined elsewhere, and that you've omitted it for brevity. If not, you may need to manually define that, depending on the context you're running this script under.

I tried your suggested code and it works well!

Thank you so much for your great help!

 

Ann

This widget could not be displayed.

I have no idea what you mean. If Kostas' answer does not help, can you explain a bit more what you're trying to do.

This widget could not be displayed.
Thanks kostas, Thats what i exactly wanted. can i perform transition associated with this custom fieldd?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

524 views 3 19
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