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

htyagi htyagi June 11, 2014

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 11, 2014

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

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 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.

htyagi htyagi June 11, 2014

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 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...

htyagi htyagi June 11, 2014

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... :-)
htyagi htyagi June 11, 2014

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