I'm attempting to write a workflow function script to automatically set a component on an issue at issue creation, anytime there isn't already a component set. Example: an end user fills out a generic IT request. Then based on our criteria we will set a component to the issue.
The problem I run into is the documentation and forums I've read all point to listing one specific component to set. We want to set several. (secondary problem, my placeholder comment comments on all issues, not just where the component is blank)
Here is what I have so far:
{code:groovy}
import com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.comments.CommentManagerimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.util.ImportUtilsimport com.atlassian.jira.user.util.DefaultUserManagerimport com.atlassian.jira.project.Projectimport com.atlassian.jira.component.ComponentAccessorimport com.onresolve.scriptrunner.runner.util.UserMessageUtilimport com.atlassian.jira.event.type.EventDispatchOption
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();MutableIssue myIssue = issueProject project = myIssue.getProjectObject()
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'SH')
if (theComponent == null) {commentManager.create( issue, user, "Generic placeholder comment", true)}
{code}
Thanks!
The specific part I was wanting to do, find an issue where the component is blank and then do something (set component), I found the answer here:
I modified mine to be == 0 and it acted on an issue where the component was blank.
I haven't tested this, but I changed it so that there were no errors. Let me know if that works.
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.event.type.EventDispatchOption
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def myIssue = event.issue as MutableIssue
Project project = myIssue.getProjectObject()
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'SH')
if (theComponent == null) {commentManager.create(myIssue, user, "Test Comment", true)}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In all my reading I was seeing that in this line you need to include the component that you want to set on the issue with the script.
def theComponent = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'SH')
The issue in our situation is we have several, 70 in our case, that we want to set automatically based on specific criteria.
My question was is there a better way to do this then what we've attempted so far? I did attempt to put all 70 in place of where it says 'SH' above. That didn't work.
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.