So I discovered that JIRA can only copy a field from parent to subtask and not the other way around without yet ANOTHER paid plugin.
We have script runner and I am trying to find a way to script out a post function that will copy a field from a subtask into the same field in the parent ticket. There are several subtasks that collect data and I want to copy each other those from their respective subtask into one place (i.e. the parent ticket). Below is what I have so far but the post function doesn't even run. Not sure what to do.
import com.atlassian.jira.component.COmponentAccessor; import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.MutableIssue; String copyFrom="customfield_13467" String copyTO="customfield_13467" def customFieldManager = ComponentAccessor.getCustomFieldManager() def userUtil = ComponentAccessor.getUserUtil() def parentIssue = (MutableIssue)issue.getParentObject() def IssueManager = ComponentAccessor.getIssueManager(); def jac = ComponentAccessor.getJiraAuthernicationContext(); def cfObj = customFieldManager.getCustomFieldObject(copyFrom) def valcfObj = issue.getCustomFieldValue(cfObj) def cf2Update = customFieldManager.getCustomFieldObject(copyTo) def valcf2Update = parentIssue.getCustomFieldValue(cf2Update) if (valcf2Update == null){ parentIssue.setCustomFieldValue(cf2Update,valcfObj) } IssueManager.updateIssue(jac.getLoggedINUser(), parentIssue, EventDispatchOption.ISSUE_UPDATED, false);
JIRA 7.1.2
ScriptRunner 4.3.16
Community moderators have prevented the ability to post new answers.
yeah that's because our stupid browser will not let me cut and paste code into these little blocks on here, so I have to type everything out line by line
Here is refactored version of your code compatible with JIRA 7. I would reccomed to use an IDE for code writing. I use Intellj IDEA.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.UpdateIssueRequest import com.atlassian.jira.issue.fields.CustomField MutableIssue parentIssue = issue.getParentObject() CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager() CustomField copyFrom = customFieldManager.getCustomFieldObject("customfield_13467") CustomField cf2Update = customFieldManager.getCustomFieldObject("customfield_13467") def valcf2Update = parentIssue.getCustomFieldValue(cf2Update) if (valcf2Update == null){ parentIssue.setCustomFieldValue(cf2Update, issue.getCustomFieldValue(copyFrom)) } ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , parentIssue , UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false).build() );
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to apply this code as a listener on the event 'issue created'...I want to copy down the value of my custom field (select list - single choice) from parent to child on creation.
Currently I get the error (issue variable is undeclared) on the line:
MutableIssue parentIssue = issue.getParentObject()
Any insight?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First of all change COmponentAccessor
to ComponentAccessor
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.