Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner update user picker single select

AbrahamA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2022

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
AbrahamA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 5, 2022

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

0 votes
Utkarsh Agarwal January 4, 2022

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

AbrahamA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 5, 2022

That was not the issue.

Suggest an answer

Log in or Sign up to answer