(Jira Server) After issue creation, post-function for auto-assignment based on component conditions
Asked by Sedanur Ozturk:

Hello,

I use JIRA Server v7.12.3.

**For a specific issue type (bug) workflow,**

I'd like to assign an issue to component lead on **initial issue creation**. But there are 2 conditions:

1. For some components it is ok to assign component lead.

2. However, for some components I'd like to assign one single user. (This user is not a component lead - here is the problem)

How can I do that by using post function on workflow transition configuration (ex: via Custom Script Post-Function) If script runner is the only way, could you please assist to write it in a simple way?

P.S: I do not want to do this auto-assignment operation by only using Component Lead function. Because it executes for all issue types. I'd like to do for a specific issue type workflow.

Thanks in advance!


Answers:
author: Laurie Sciutti
body: Hi [@Sedanur Ozturk](/t5/user/viewprofilepage/user-id/5531691) and welcome to the Community! Have you thought about using an automation rule rather than a post-function script?

comments: author: Sedanur Ozturk
body: Hi [@Laurie Sciutti](/t5/user/viewprofilepage/user-id/1137433) , thank you for welcoming :)

I'm not system admin and need to run some procedures for adding Automation app. And I'm not sure if this app is compatible or not. So that'd be the last option for me for now.

Thanks indeed!


author: Stefan Salzl
body: Hi [@Sedanur Ozturk](/t5/user/viewprofilepage/user-id/5531691) - welcome to the community,

should be possible with a custom script in post function. Does the issue type you would like to apply this have its own workflow? Or is it a shared workflow for several issue types?

Best  
Stefan

comments: author: Stefan Salzl
body: See a first pitch of such a script below. This is just a draft for you to figure out the elements and steps that could lead to your solution.

Furthermore I always took the first component (as an issue could possible consist of more than 1 components).

```


import com.atlassian.jira.event.type.EventDispatchOption

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.component.ComponentAccessor





def issueManager = ComponentAccessor.getComponent(IssueManager)

def cfManager = ComponentAccessor.getComponent(CustomFieldManager)





def leadUser = issue.components.getAt(0).lead

def issueComponent = issue.components.getAt(0)






log.warn issue.issueTypeId.equals("10000")

log.warn issue.components.getAt(0).name





if (issue.issueTypeId.equals("10000")) { // -- > ID of issueType - you need to change to the ID of your issueType

    if(issueComponent.name.equals("Component 1")){

        issue.setAssignee("<any user you want, either component lead or other ApplicationUserObject>")

        log.warn "juhuuu"

    }

    else if(issueComponent.name.equals("anyOtherComponent")){

        log.warn "here you go"

    }

    else{

        log.warn "nothing happens"

    }

}




issueManager.updateIssue(Users.loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)











```


Tags: adaptavist

assignee

auto

component

data-center

jira-data-center

post-function

scriptrunner