This article provides the code snippet to set a single user picker field from the email address available in a free text field, using the Set field value (JMWE app) post-function.
Navigate to the intended workflow to make the necessary changes in the edit mode.
Select the required transition.
Select the Post Functions tab and click Add post function
.
Add the “Set field value (JMWE app)” post-function.
Select the target single user picker field in “Field” and select “Value type” as “Groovy Expression”.
Add the below Groovy script in “Value”:
import com.atlassian.jira.bc.user.search.UserSearchService def userSearchService = ComponentAccessor.getComponent(UserSearchService) def users = userSearchService.findUsersByEmail(issue.getAsString("customfield_10300")) users[0] |
Replace 10300 in line #4 with the id of the text field, which has the email address.
Click Add and publish your workflow.
Note: The script returns null in the below two scenarios:
The text field is empty.
No user is found for the email address present in the text field.