I have a custom field of type project picker and i want to get the value selected, here my code
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.project.Project
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11001");// ID of my custom field.
def value = (String)issue.getCustomFieldValue(customField);
log.info("the project selected is"+value)
and i get an error : the variable issue is undeclared
any help !!
Hi Madhi,
Yes, the error seems correct. If you are doing this in the script console, you need to get the issue that you want to work with. Something like this:
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.issueManager
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11001")
def issue = issueManager.getIssueByCurrentKey("GIB-1") // your issue key here
def value = (String) issue.getCustomFieldValue(customField)
log.info("the project selected is" + value)
Regards,
Josh
Hi Joshua,
thank you i works fine i can get the value of the project selected in the project picker field it return the key of a project slected in a transition screen.
now I want to clone this issue in the project selected, write this code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Logger
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
def issueManager = ComponentAccessor.issueManager
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11001")
def issue = issueManager.getIssueByCurrentKey("NEXT-4") // the issue key here
def value = (String) issue.getCustomFieldValue(customField)
log.warn("the key project selected is" + value)
//clone issue
def originalIssueKey = issueManager.getIssueByCurrentKey("NEXT-4")
def destinationProjectKey = ComponentAccessor.projectManager.getProjectObjByKey("value")
log.warn("the distination is " + destinationProjectKey)
cloneIssue(originalIssueKey, destinationProjectKey)
void cloneIssue (MutableIssue issue, Project project) {
def params = [
issue : issue,
(CloneIssue.FIELD_TARGET_PROJECT) : project.key,
(CloneIssue.FIELD_SELECTED_FIELDS) : null, //clone all the fields
] as Map<String, Object>
new CloneIssue().doScript(params)
}
but I get errors, java.lang.NullPointerException: Cannot get property 'key' on null object
any idea please !!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure you have the right project key? For this line, you have the project key as "value"
def destinationProject = ComponentAccessor.projectManager.getProjectObjByKey("value")
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
def issueManager = ComponentAccessor.issueManager
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11001")
def issue = issueManager.getIssueByCurrentKey("NEXT-4") // the issue key here
def value = (String) issue.getCustomFieldValue(customField)
log.warn("the key project selected is" + value)
//clone issue
def originalIssue = issueManager.getIssueByCurrentKey("NEXT-4")
def destinationProject = ComponentAccessor.projectManager.getProjectObjByKey("value")
log.warn("the distination is " + destinationProject)
cloneIssue(originalIssue, destinationProject)
void cloneIssue(MutableIssue issue, Project project) {
def params = [
issue : issue,
(CloneIssue.FIELD_TARGET_PROJECT) : project.key,
(CloneIssue.FIELD_SELECTED_FIELDS): null, //clone all the fields
] as Map<String, Object>
new CloneIssue().doScript(params)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it works thanks
the error was in the project key value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.