Hi guys
I'm using Jira service management data center.
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?
Or do you have any other suggestion to do this?
Hi @Mahdi Mohammadnejad ,
If you are using ScriptRunner, you can start using Insight Manager.
Once you set the insight manager you can use the following script in a scripted listener:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.event.type.EventDispatchOption
import customRiadaLibraries.insightmanager.InsightManagerForScriptrunner
//Get the InsightManager
@WithPlugin("com.riadalabs.jira.plugins.insight")
InsightManagerForScriptrunner im = new InsightManagerForScriptrunner()
//Get necessary managers
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
//Get the event issue of the listener
def issue = event.issue
//Get a user (an admin for example or the current user)
def adminUser = ComponentAccessor.userManager.getUserByName("admin")
//Get your manager custom field
CustomField managerCF = customFieldManager.getCustomFieldObject("manager_customfield ID")
//Get the issue reporter
def reporter = issue.reporter.displayName
//Get the employee using Insight manager
def employee = im.iql(<ID of your Asset schema>,"objectTypeId = <ID of your object type Employee> AND Name =\"${reporter}\"")[0]
//Get the manager from the employee object using insight manager
def manager = im.getObjectAttributeValues(employee, "Manager")[0] as String
//Get the jira user using manager
def user = ComponentAccessor.getUserManager().getUserByName(manager)
//Set the custom field with the manager
issue.setCustomFieldValue(managerCF, user)
//update the issue
issueManager.updateIssue(adminUser,issue, EventDispatchOption.ISSUE_UPDATED,false)
I did not test the script si if you have any errors or questions dont hesitate to ask again.
Taha
Or you can simply use Insight post functions and go for "Set a Jira custom field with the attribute value from a selected object"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your answer. I don't want to select object manually.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If i use post function how could i update t during workflow?
I mean if i change reporter after creation of issue how could i update atribute of object in custom field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To answer you first comment, you don't have to choose manually. The aim is to use the post function to update the manager field based on the reporter field
To answer your second comment the best way to do it is to use the scripted listener I sent before. But if you are not confortable with scripting, here's a suggestion :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @Taha El Majidi
Thanks for your reply.
Let me check it. I think your 2nd suggestion is better for me.
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.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.