Hi,
I am trying to return a custom field value from a different issue, I have the Issue ID stored in a Custom Field on the current issue.
I am running JIRA 5.2
I am using the Script Runner Plugin to create a subtask, when creating the subtask I want to retrieve the value of a field, from the issue stored in my customfield.
e.g.
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 import com.atlassian.jira.component.ComponentAccessor //Issue that I would like to access to get the field value def TargetIssueID = cfValues['Target Issue'] //Custom Field that I am trying to retrieve the value from: CustomField request_type = customFieldManager.getCustomFieldObjectByName('Supported Service') //Here the code will be to retrieve the value of "Supported Service" from the "Target Issue" //Then Setting the field in the subtask issue.setCustomFieldValue(request_type, target_Issue_request_type_value)
Any help greatly appreciated..
Community moderators have prevented the ability to post new answers.
I have made it work using
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 import com.atlassian.jira.component.ComponentAccessor CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager() def cf = cfValues['Issue ID Link'] def issueManager = ComponentAccessor.getIssueManager() //cf being field that contains the Issue ID def targetIssue = issueManager.getIssueObject(cf) CustomField request_type = customFieldManager.getCustomFieldObjectByName('Custom Field 1 to Set') def request_type_value = targetIssue.getCustomFieldValue(request_type) // set the value of Custom Field 1 in the current issue's customField issue.setCustomFieldValue(request_type,request_type_value)
Thanks to Thanos.
Also the fields that are being copied over, they're not from the Linked Issue or Target Issue are they? or Parent.. as I need them from a Targeted Issue not parent..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing is that you need to think about where this is running. You've not said if it's a post-function, listener or something else, and that matters because the context of "which issue" is critical here.
Your first line that gets the targetIssueID is ok, but as it's going to contain a string or an array, you're going to need to convert it to an issue object before it's of any use.
request_type is fine, it's a custom field handle
The last line is where the context matters. What issue? Where does that "issue" object come from? If you are doing this in a post-function or listener, then that issue object will be the current issue that the user has just transitioned.
Your code is broadly correct, but you need to think through the process and context.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is a scripted Post Function - using the Scriptrunne plugin "Create a Subtask"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The issue itself is in a different project, issue.setCustomFieldValue is being used at the end to SET the field in the NEW Subtask that is being created, using the value that is retrieved from the Target Issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As this is a Scripted Post Function - "Create a Subtask" my main task is to set the field values as the new subtask is created. I can do Parents to Subtask but I need to do Linked Issue to Subtask. The Custom Field Target Issue will only contain a single Issue ID per transition so that is fine. I just need a method, or a piece of code which I can use to access the Target Issue and retrieve Custom Field Values, as you would from Parent. e.g. For Parent I use: def request_type_value = transientVars["issue"].getCustomFieldValue(request_type) But I cannot use above to instead go to a specific Issue ID..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tried to use def targetIssue = IssueManager.getIssueObject(targetIssueID) But it fails and does not create a subtask.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jeff, Thanks I appreciat your help, I had tried your code yesterday but failed to make it work, Your code, would you need to save the script and set it as a file path? or where would you use it then? just to clarify.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sy, I gave you the code yesterday to create a subtask and copy all the fields. Instead of using the built in "crate subtask" use my code rather than trying to do it in two different scripts. I am not sure why you would want to do this in two different scripts? and if you don't want to copy all the fields, just create a list of fields you want to copy and loop over them.
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.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.