Hello!
I have a project that we store some user hierarchy
I try to set assignee in new issue in project TEST from this project, depending on customfield value.
But as a result i receive null and Assignee is unassigned
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.ComponentManager
// any task where i want to change assignee
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("TEST-429");
log.warn(issue.key+ " id " +issue.id)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def finId = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_15208"))
Node fid = new XmlParser().parseText(finId)
long fcpid = Long.parseLong(fid.value.text());
// issue with
Issue fcpIssue = issueManager.getIssueObject(fcpid);
//fields from fcp
def user = fcpIssue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_15200"))?.username
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(user))
How to use setAssignee properly?
Can you output the result of the following line to the log and make sure you are getting the value you want?
def user = fcpIssue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_15200"))?.username
Depending on the result of the above, we could confirm if you can set the assignee.
I would start with getting the value of the following:
def finId = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_15208"))
Node fid = new XmlParser().parseText(finId)
long fcpid = Long.parseLong(fid.value.text());
Confirm you are getting the correct value first before we proceed any further. I would like to ask why you are not just parsing the issue-key directly from your customfield or something similar.
I will need more context to be able to help you further with the above.
Cheers.
logs:
WARN [runner.AbstractScriptRunner]: TEST-429 id 193718
WARN [runner.AbstractScriptRunner]: fid= content[attributes={}; value=[value[attributes={}; value=[206189]]]]
WARN [runner.AbstractScriptRunner]: fcpid= 206189
WARN [runner.AbstractScriptRunner]: user prokashik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
tried with
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))
same result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try:
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))
Ensure you persist the value with an issue update event. For example:
assetOwner = userManager.getUserByKey('myuser')
log.warn(assetOwner)
issue.setCustomFieldValue(assetOwnerField, assetOwner)
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
The last line ensures that JIRA persists your change in a post-function or event.
Can you give this a try and confirm if this is the same as what you are aiming for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I find my problem
def user = fcpIssue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_15200"))?.key
log.warn("user " +user)
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Thank You a lot for help, @Ismael Jimoh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems almost certain the the username that is returned from the custom_field is resulting in a value that doesn't return a user from the getUserByName() call. That is where I would focus. Make sure that you are getting a String value that is a username that can be found by the call.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ready script for our free plugin Mygroovy
import com.atlassian.jira.component.ComponentAccessor
//def issue = ComponentAccessor.issueManager.getIssueObject('CUSTOM-17405')
def someField = getCustomFieldValue(issue, 43312) //field id
if (!someField){
issue.setAssignee(ass1)
} else{
if(someField.optionId == 38538){
issue.setAssignee(ass2)
}
}
def getCustomFieldValue(issue, Long fieldId) {
//ComponentAccessor.customFieldManager.getCustomFieldObject(fieldId)?.getValue(issue)
issue.getCustomFieldValue(ComponentAccessor.customFieldManager.getCustomFieldObject(fieldId))
}
ps. By the way, here we have scripted the templates of the scripts, the most frequently usecases, just copy and paste what u need. https://github.com/mailru/jira-scripts/tree/master/JIRA%20groovy%20templates
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.
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.