get "userName" / "userkey" from custom field with "userdisplayName"

Stefan Bunke March 3, 2016

Hello,

we want to assign an issue to a user from a custom field (From anpother plugin (CRM). The field only displays the full display name) using the behaviours/scriptrunner plugin.

see image: https://picload.org/image/widgcir/j1.jpg  (Attaching images here was not possible?! -> Server Error)

I think we need to get the "userName" / "userkey" (e.g.: FF) from the custom field with the "userdisplayName" (e.g.: Fred Flintstone) to set the Assignee afterwards.

I hope someone could help.

 

Or is the "Issue Alternative Assignee"-Plugin capable of that? (we have Jira V7.1.1)

 

kind regards

Stefan

3 answers

1 accepted

0 votes
Answer accepted
Stefan Bunke March 7, 2016

yes this "findUserNames" seems to be what we need - but we are too unskilled to implement this in our behaviour.

Can you (or someone else)  please give us an example what classes we have to import and how the syntax should be (we are no programmers) ?

This is the (not working) serverside script we have right now:

import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.user.ApplicationUsers
//Line below does not work
//getFieldById(ASSIGNEE).setFormValue(getFieldById("customfield_12239").getValue())


//Line below is for testing only
getFieldById("comment").setFormValue(getFieldById("customfield_12239").getValue())

thx in advance

JamieA
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.
March 7, 2016

Could you add your supplementary questions as comments rather than as answers? 

I think you are looking for an example of how to look up a user by display name, so here is one (I don't know what the code above is supposed to do):

import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor

def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def users = userSearchService.findUsersByFullName("Mr Admin")

if (users) {
    users.first() // an ApplicationUser (in jira 7)
}
else {
    // no users found with that display name
}
Like SWAPNIL SRIVASTAV likes this
Stefan Bunke March 7, 2016

oh sorry, will do next time/s.

this is exactly what we need =) An example.

Thank you & kind regards

Stefan

SWAPNIL SRIVASTAV June 1, 2020

Hello @JamieA ,

Could you please help me fetch a username from a String which is actually the Full Name/Display name of the user?

Regards

Swapnil Srivastav

SWAPNIL SRIVASTAV June 1, 2020

@JamieA : 

Nevermind. I tried the above script and it worked for me. Thank you

0 votes
Stefan Bunke March 6, 2016

Hello Jamie,

thanks for your answer. We already did that, but the field only returns a string (equal to the full display username). So we need somehow to get the user behind that string.

When we write the value in a comment field with:

comment.setFormValue(getFieldById("customfield_12239"))

we get

Form field ID: customfield_12239, value: Fred Flintstone

When we try to put this value in the assigne field its not working.

regards

JamieA
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.
March 6, 2016
0 votes
JamieA
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.
March 6, 2016

I don't know anything about that plugin, but most likely it will give you an ApplicationUser object if you call issue.getCustomFieldValue on that CF. That would be the way to go rather than trying to look up a key by display name. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events