Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner update user picker single select

Hello

I need to set the value of user picker

I have PMUser of type ApplicationUser.

I am trying to set the value of user picker. and tried 2 ways:

Method1:

def PMField = customFieldManager.getCustomFieldObjectsByName("My PM")

thisIssue.setCustomFieldValue(psirtPMField[0],PMUser)

 

Method2:
def PMFieldSingle = customFieldManager.getCustomFieldObjectByName("My PM")

thisIssue.setCustomFieldValue(psirtPMFieldSingle,PMUser)

 

I am getting cannot find matching method for setCustomFieldValue for both ways. setCustomFieldValue should have customfield and object as parameters right. Where could be the issue.

Please let me know.

Thanks

Abe

 

2 answers

1 accepted

0 votes
Answer accepted

For anyone having similar issue, I was using Issue instead of MutableIssue. 

Hi @AbrahamA ,

getCustomFieldValue() expects you to pass in a singular custom field object. Are you passing in a collection of custom field objects, because you must be using getCustomFieldObjectsByName() to get the user field. That seems to be causing the error.

If yes, you can try something like:

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()
def user1 = "user name"
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def userCf = customFieldManager.getCustomFieldObjectByName("field Name")
def user = userManager.getUserByName(user1)

issue.setCustomFieldValue(userCf, user)
ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

Kind Regards
Utkarsh

That was not the issue.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you