I have a transition that creates a bunch of sub tasks. when a particular subtask is created, I want to create a link issue using the "Clones an issue, and links [ScriptRunner]" post function. Under the condition section, I have this:
issue.summary.matches("MM conducts Table 3 Training(.*)") && issue.issueType.name == "PCT Sub-Task"
this works fine when I tested it with additional issue actions and set the summary to below
issue.summary = 'Test'
Now, I have a custom field that I want to copy from the parent task that triggered the subtask and this linked task, so I created the script below
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
Issue parentIssue = issue.getParentObject()
def proj = ComponentAccessor.getProjectManager().getProjectByCurrentKey("PCT").id
def pct = parentIssue.issueType.name as String
def cfMgr = ComponentAccessor.getCustomFieldManager()
def newCHAOCf = cfMgr.getCustomFieldObjects(proj, pct).find {it.name == 'New CH/AO'}
def newCHAO = parentIssue.getCustomFieldValue(newCHAOCf) as ApplicationUser
MutableIssue mm_task = ComponentAccessor.getIssueFactory().getIssue()
mm_task.summary = ('Conduct ILT for New CH/AO' + ' [' + newCHAO.getDisplayName() + ']') as String
I am getting the error below:
java.lang.NullPointerException: Cannot get property 'issueType' on null object
it seems like it is not getting the parent issue object properly. Any input would be much apprecaited. Thank you.
Update: the code below is what ended up working for me:
import com.atlassian.jira.user.ApplicationUser
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'New CH/AO'}
def ch_ao_val = sourceIssue.getCustomFieldValue(cf) as ApplicationUser
def summary = ('Conduct ILT for New CH/AO' + ' [' + ch_ao_val.getDisplayName() + ']') as String
def description = ('MM Team, AE roles submitted on' + ' [' + ch_ao_val.getDisplayName() + ']') as String
issue.summary = summary
issue.description = description
I am not sure why issue.summary = 'some string' works but
Hi @Lisbon Cruz
For your requirement, you must first validate whether the current issue is a Sub-task. This is missing in your code, which is why it is failing.
Below is a sample working code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def sampleTextField = customFieldManager.getCustomFieldObjectsByName('Sample Text Field').first()
if (issue.isSubTask()) {
def parent = issue.parentObject
def parentFieldValue = parent.getCustomFieldValue(sampleTextField) as String
issue.setCustomFieldValue(sampleTextField, parentFieldValue)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
if (issue.subTask) {
def parent = issue.parentObject
issue.set {
setCustomFieldValue('Sample Text Field', parent.getCustomFieldValue('Sample Text Field'))
}
}
Below is a screenshot of the configuration using HAPI:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good Morning,
It looks like I do have scriptrunner 8.7.0. Do I have to add the custom script post function in addition to clones issues? Here is my current configuration:
Would I have to add the "HAPI" Script above in addition? Also, the reason I am doing it this way, rather than just using project automation is to be able to grab the custom field value of the "users" custom field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried the first code and it worked. But I need to set the summary and description to something custom, hence why I am using scriptrunner. Here's the code that I have:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def issuemgr = ComponentAccessor.issueManager
def log_in_usr = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def cus_field_mgr = ComponentAccessor.customFieldManager
def new_ch_ao = customFieldManager.getCustomFieldObjectsByName('New CH/AO').first()
if (issue.isSubTask()) {
def parent = issue.parentObject
def ch_ao_val = parent.getCustomFieldValue(new_ch_ao) as String
issue.setCustomFieldValue(new_ch_ao, ch_ao_val)
issue.setDescription('MM Team, AE roles submitted on' + ' [' + ch_ao_val + ']') as String
issue.setSummary('Conduct ILT for New CH/AO' + ' [' + ch_ao_val + ']') as String
issuemgr.updateIssue(log_in_usr, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
I just put this under the "Additional issue actions" in "Clones an issue, and links [ScriptRunner]" post function. I am getting the subtasks summary, despite setting the summary to something custom.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.