/** This example script listener script should be conifgured to run on the issue created event for a Jira Service Management project, in order to set a user in a user picker field who was specified by name in the issue description. * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */importjava.util.regex.Matcher;importjava.util.regex.Pattern;// Get all custom fieldsdefcustomFields=get("/rest/api/3/field").asObject(List).body.findAll{(itasMap).custom}asList<Map>// Get the ID for your user picker field fielddefuserPickerField=customFields.find{it.name=='Demo User Picker'}?.id// Change to name of your field here// Get the current issue summary and todays datedefdescriptionVal=issue.fields.description// Define the regular expression pattern used to find the user in the description textdefregex='(?<=The owner of this ticket is:).*';Patternpattern=Pattern.compile(regex);Matchermatcher=pattern.matcher(descriptionVal);// Extract the name of the user after the text The owner of this ticket is:if(matcher.find()){defuser=matcher.group(0)// Find the user details for the user matched from the descriptiondefuserSearchRequest=get("/rest/api/3/user/search").queryString("query",user).asObject(List)// Assert that the API call to the user search API returned a success responseassertuserSearchRequest.status==200// Get the accountId for the user returned by the searchdefuserAccountId=userSearchRequest.body.accountId[0]// Update the issue to set the user picker field to the returned userdefsetUserPickerField=put('/rest/api/3/issue/'+issue.key).header('Content-Type','application/json').body([fields:[(userPickerField):[id:userAccountId],]]).asString()}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.