I use the following code to copy parent description to a scripted field called Parent Description. I need the same thing but now i want to copy a user picker customfield_14468 to scripted filed called PM. How can i call/define parents customfield just like i called parents description in below code? Any thoughts?
I put this code in the scripted field.
Thanks
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
if (issue.getProjectObject().getKey() == 'MCO')
{
def field =ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent description")
def newfield = issue.getParentObject().description;
return newfield;
}
You can do it like so:
def parentCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(14468)
return issue.getParentObject().getCustomFieldValue(parentCf)
Just make sure your scripted field is using a proper template and searcher if you want the data to be displayed correctly.
Hi @Ivan Tovbin
I replaced with your suggested code and i get the error as attached.
I chose the template as user picker single
When u say searcher, what are you referring to?
I want the code to work so that parents custom field value will be copied over to a scripted field. So whenever i update parent, the updates will flow thru the new scripted field. it was successful when i copied parent description and summary
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I modified code a little to this. User picker from parent shows a user and this new scripted filed is suppose to show the same user. instead it shows as anonymous. please see attched screenshot
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
if (issue.getProjectObject().getKey() == 'MCO')
{
def field =ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Program Manager.")
def parentCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14468")
return parentCf
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, Scriptrunner can be very annoying at times with its Static Type Checking not always being accurate. In this case I'm quite certain you can pretty much ignore this error. Or you can change:
getCustomFieldObject(14468)
to
getCustomFieldObject(14468.toLong())
and this should make this error go away.
By searcher I mean a search template which is being used to to index and searth this field. For a user picker type custom field make sure the search template is set to 'User Picker & Group Searcher'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yep, your user picker data is rendered as 'Anonimous' because an incorrect search template is set for this field. Check the above comment to fix it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, your code is wrong, because it returns a CustomField object instead of its value for a given issue. Please try the code I provided and see if it works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@KRC Great news! Please mark this solution as "Accepted" if it resolved your issue.
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.