I want to assign issues in 1st step of workflow to reporter's manager automatically to approve issue. Information of users and their managers are in Asset. In assets I have an object schema with "Employee" object type. Information of users are under this object type. In this object type i have 2 attributes. "Username" and "Manager".
I want to fill "manager_customfield" automatically.
For example Reporter is "User1", if "Username" attribute is equal with reporter then fill "manager_customfield" with "Manager" attribute.
To do this i find a script but it's not complete and i couldn't run it. could you please help me?
import org.apache.catalina.Manager
import com.atlassian.sal.api.user.UserManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def reporterUsername = issue.reporter?.name
def manager = getManagerFromAssets(reporterUsername)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManafer = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cf = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10500")
issue.setCustomFieldValue(cf,manager)
issueManafer.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
def getManagerFromAssets(reporterUsername) {
def assetObjects = queryAssets()
def manager = assetObjects.find { it.username == reporterUsername }?.manager
return manager
}
def queryAssets() {
def assetService = ComponentAccessor.getComponent("***")
return assetService.getAllAssets()
}