Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
I have a problem and I don't know how to solve it. Maybe you have any ideas?
I would like to automate Jira Workflow and create automatic assignment in some situations to make sure that case is left unassigned.
Let's say I have custom field in Jira Software called Service Team with options like: Logistic, IT, Finance, etc.
For each Service Team I have dedicated person who is responsible for accepting tickets. It's always same person for each Service Team i.e. for Logistic it's Andrew, for Finance it's Jake and so on.
Do you know how I can manage that after workflow transition to a specific state case will be assigned automatically to specific person depends on Service Team custom field value?
I tried with post function but I couldn't find option to make it.
Do you have any advice for me?
Thanks in advance
Hi Wojtek,
There's a couple of ways to do this:
1) Create a scripted post function that will set an assignee depending on your custom field value. This will require a 3rd party addon like ScriptRunner or JMWE.
2) Create an automation rule that will trigger when your issue is transitioned and set an assignee based on your custom field value. Automation for Jira is required for this approach.
3) If your are using Jira Service Desk, then you can do it using standard JSD automation which is available out of the box.
Please mark the 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.
Hi Ivan,
I am trying to do option 1, as my client has ScriptRunner but does not want to purchase any other add-ons. I am pretty new to using scriptrunner, how would I go about writing the code for this? I can't find it anywhere online
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Callum Carlile _Automation Consultants_
Sure thing. Please advise your custom field type and when do you want this to trigger?
Cheers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The custom field is a single user picker. I would like this selected user to be assigned to a sub-task which is created automatically from a post function in a different workflow (I assume this is what you mean by trigger)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Assuming your custom field is IN your sub-task (and not in its parent issue for example) the code would be as follows:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName")
ApplicationUser cfValue = issue.getCustomFieldValue(customField)
if (cfValue){
issue.setAssignee(cfValue)
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
However, if your subtask is also created via script, the best approach would be to modify that script so the subtask is created already with an assignee set.
Otherwise use the code I provided as a post function for your subtask's 'Create' transition. Make sure you place this post function last.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ivan Tovbinis it possible to create similar script but for a bit complex conditions?
I want to set auto assignment for issue for certain user depending on custom field value (cascade type, two values).
For example, if value = A-a or B-b or C-c etc. assign to user1
if value = D-d or E-e assign to user2
How it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ivan Tovbin how can I do this using option 3?
3) If your are using Jira Service Desk, then you can do it using standard JSD automation which is available out of the box.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I get an error ComponentAccessor has not been initialised.
how to resolve it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Go to the project setting
Automations
Create new rule
Issue created
Assign issue << Specify user << Name of the user
in conditions
issue fields condition
field: service team then Set the condition :equal and Value : to one of your values
rememeber you have to create new rule for each user.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
finally a good solution
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
We have a requirement, where 2 projects uses the same workkflow and it uses a post function by JMWE of auto assignment of user as assignee, when the user transition an issue.
Is there any way via scriptrunner, that we do not make changes to the workflow, but restrict this post function via scriptrunner for 1 project?
Thank You
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Swati Gupta Why don't you simply use the "Conditional execution" feature of the JMWE post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Thanks for the suggestion, but can you please let me know how to do it?
Because when I add condition for current user, restricting JIRA project, then the transition is not visible for the specific project.
I would want to use condition in postfunction, but dont get the option Please help me with the solution.
Thank You
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Swati Gupta "Conditional Execution" is an option of every JMWE post-function - just look closely at the post-function configuration screen, you'll find it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Thanks for your comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried script for post function requirement:
// Imports
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.MutableIssue
// import for debug only
import org.apache.log4j.Logger
import org.apache.log4j.Level
log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
//Current issue - uncomment for post-function
Issue parentIssue = issue
//Get Value of Required Reviewers - Replace "XXXXX" in "customfield_XXXXX" with the actual value of your custom field
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
String customfieldID_MultiUserFieldName = 'customfield_18410'
CustomField customfield_MultiUserFieldName = customFieldManager.getCustomFieldObject(customfieldID_MultiUserFieldName)
Object customfieldIDValue_MultiUserFieldName = (ArrayList) parentIssue.getCustomFieldValue(customfield_MultiUserFieldName)
//Pre-define JQL Parser functions
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def activeUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Pre-define Sub-Task Generation functions
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
//Get Values to copy from Parent
def summary = "Subtask for " + parentIssue.getSummary()
def dueDate = parentIssue.getDueDate()
def project = parentIssue.getProjectObject()
//Define Sub-Task Type - Replace "PUT CUSTOM FIELD NAME HERE" with the actual name you're using for your custom field
def issueTypeId = constantManager.getAllIssueTypeObjects().find{it.getName() == "products"}.id
//Iterate through and create subtasks
for (int i = 0; i < customfieldIDValue_MultiUserFieldName.size(); i++){
ApplicationUser reviewerObject = customfieldIDValue_MultiUserFieldName[i] as ApplicationUser
String reviewer = reviewerObject?.name
log.debug reviewer
//do not create sub-tasks if a sub-task already exists and has a certain Resolution
def query = queryParser.parseQuery("parent = ${parentIssue} and assignee = ${reviewer} and (resolution = Abstained or resolution = Approved or resolution = Unresolved)")
log.debug query
def search = searchService.search(activeUser, query, PagerFilter.getUnlimitedFilter())
def total = search.total
log.debug total
if (total == 0){
//Create core Sub-Task Values
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setProjectObject(project)
newSubTask.setIssueTypeId(issueTypeId)
newSubTask.setParentObject(parentIssue)
newSubTask.setSummary(summary)
newSubTask.setDueDate(dueDate)
newSubTask.setReporter(activeUser)
//Assign Sub-Task
newSubTask.setAssigneeId(reviewer)
log.debug newSubTask.assigneeId
//Create Sub-Task
def newIssueParams = ["issue" : newSubTask] as Map
log.debug "Creating task for ${reviewer}"
def createdSubTask = issueManager.createIssueObject(activeUser, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, createdSubTask, activeUser)
}
}
======================================================
Below is the error:
2022-06-12 10:54:17,052 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue TPFSPP-2 for user 'ac-swagup'. View here: https://jira-dev.assaabloy.net/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=Software+Simplified+Workflow+for+Project+TPFSPP&descriptorTab=postfunctions&workflowTransition=11&highlight=1 java.lang.NullPointerException: Cannot get property 'id' on null object at Script162.run(Script162.groovy:45)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
May I ask you the code of script runner to assign a specific assignee based on custom fields? If it is possible through 'workflow properties', please let me know!!
Thank you for your help!
Best regards,
Jenny
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ivan,
thanks for your reply. I used your second proposal and it works great. Thanks for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Wojtek Misiarz - Could you please help how to achieve this.
If I create a Jira Issue and select a module and sub-module, can the issue be auto-assigned to a particular user based on the sub-module?
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.