How to retrieve the value of custom field of type label.??

Dear support,

we had created a custom field of type text then we were able to retreive the value in validtor script (groovy , script runner). While changing it to the label field , it gives below exception of hash...

Exception: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.getIssueObject() is applicable for argument types: (java.util.LinkedHashSet) values: [[PRO-43]]
Possible solutions: getIssueObject(java.lang.Long), getIssueObject(java.lang.String), getIssueObjects(java.util.Collection)

code is beloe... if "Parent Task ID" created text type then code is ok.. while if it is Label type then throws exceptions..

+++++++++++++

import org.apache.log4j.Category

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.issuetype.IssueType

import com.atlassian.jira.issue.IssueFactory

import com.atlassian.jira.issue.IssueKey

import com.atlassian.jira.issue.IssueImpl

def parentTaskID = cfValues['Parent Task ID'];

if (parentTaskID == null || parentTaskID == '') {

return true;

} else {

def parentIssue = ComponentAccessor.getIssueManager().

getIssueObject(parentTaskID);

def isValid = parentIssue != null &&

parentIssue.projectObject.key == issue.projectObject.key && (parentIssue.issueTypeObject.name == 'Review Task' || parentIssue.issueTypeObject.name == 'Test Task');

return isValid;

}

++++++++++++++++++++++++++

1 answer

1 vote
Henning Tietgens Community Champion Jun 11, 2014

Try changing the line def parentTaskID = cfValues['Parent Task ID']; to
def parentTaskID = cfValues['Parent Task ID'].getLabel();

Henning Tietgens Community Champion Jun 11, 2014

cfValues[] returns the object which is stored for the custom field. For text field this is a String, for Label fields it's a Label object. To get the text of the Label (a String) you have to use getLabel() on the Label object.

HiHenning..

it is giving below now...

2014-06-12 13:23:09,295 http-bio-11000-exec-4 ERROR jiraad 803x6575x1 1yjgt95 10.202.29.46 /secure/QuickCreateIssue.jspa [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashSet.getLabel() is applicable for argument types: () values: []
Possible solutions: getClass(), getAt(java.lang.String), getAt(java.lang.String)

code for validator is

+++++++

import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueKey
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.security.*

//def parentTaskIDCF = customFieldManager.getCustomFieldObject('customfield_10200');//write your own custom field id here 10105.. 10200 for label

def parentTaskID = cfValues['Parent ID'].getLabel();
if (parentTaskID == null || parentTaskID == '') {
    return true;
} else {
    def parentIssue = ComponentAccessor.getIssueManager().
		getIssueObject(parentTaskID);
    def isValid = parentIssue != null && 
         parentIssue.projectObject.key == issue.projectObject.key && (parentIssue.issueTypeObject.name == 'Review Task' || parentIssue.issueTypeObject.name == 'Test Task');
    return isValid;
}



++++++++++++++

Code for post function
+++++++++++++++++
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueKey
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.security.*

def ComponentManager componentManager = ComponentManager.getInstance();
def customFieldManager = componentManager.getCustomFieldManager();
def parentTaskIDCF = customFieldManager.getCustomFieldObject('customfield_10200');//write your own custom field id here 10105.. 10200 for label
def parentTaskID = issue.getCustomFieldValue(parentTaskIDCF);
println "MY VALUES" + parentTaskIDCF ;
if (parentTaskID == null || parentTaskID == '') {
return true;
} else {
def issueManager = ComponentAccessor.getIssueManager();
def parentIssue = issueManager.getIssueObject(parentTaskID);
def isParentIssueValid = parentIssue != null &&
parentIssue.projectObject.key == issue.projectObject.key &&
(parentIssue.issueTypeObject.name == 'Review Task' ||
parentIssue.issueTypeObject.name == 'Test Task');
if (isParentIssueValid) {
def issueLinkManager = ComponentAccessor.getIssueLinkManager();
def issueLinkTypeManager = componentManager.
getComponentInstanceOfType(IssueLinkTypeManager.class);
def issueLinkType = issueLinkTypeManager.getIssueLinkTypesByName('found in').get(0);
def authenticationContext = componentManager.
getComponentInstanceOfType(JiraAuthenticationContext.class);

issueLinkManager.createIssueLink(issue.id, parentIssue.id, issueLinkType.id, 1L, authenticationContext.getLoggedInUser());
}
}


Henning Tietgens Community Champion Jun 11, 2014

Ah sorry, it's no a Label on it's own, it's a list of Label objects (because you are able to enter multiple labels) you get. If you want to execute your code for each label you can write

parentTaskID.each { id ->
    // put your code here, access each single label text as id.getLabel()
}

If not, you have to think about which label you want to access...

HI..

Not working as a developer so lacking this skill, yet tried but not succeeded..

def parentTaskIDList = cfValues['Parent ID'];
parentTaskIDList.each{ id -> parentTaskID as id.getLabel();
if (parentTaskID == null || parentTaskID == '') {
    return true;
} else {
    def parentIssue = ComponentAccessor.getIssueManager().
		getIssueObject(parentTaskID);
    def isValid = parentIssue != null && 
         parentIssue.projectObject.key == issue.projectObject.key && (parentIssue.issueTypeObject.name == 'Review Task' || parentIssue.issueTypeObject.name == 'Test Task');
    return isValid;
 }
};



+++++++++++
Exception found is below
+++++++++++++

2014-06-12 14:14:26,295 http-bio-11000-exec-34 ERROR jiraad 854x7273x1 1o7qey7 10.202.29.46 /secure/QuickCreateIssue.jspa [groovy.canned.utils.ConditionUtils] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script28.groovy: 16: expecting '}', found '(' @ line 16, column 57.
-> parentTaskID as id.getLabel();
^

1 error







Can you rectify the program... :-)

Hi

Henning,

Thanks a lot , it has been concluded now.. syntax is corrected and working perfectly.. Many Thanks


Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

82 views 0 5
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