/** This example script console script should be conifgured to run as the ScriptRunner Add-On User and shows how to search for a user and set them as the reporter when creating an issue.* "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." */defprojectKey='<Project Key Here>'defprojectId=get("/rest/api/2/project/${projectKey}").asObject(Map).body.iddeftaskType=get("/rest/api/2/issuetype/project?projectId=${projectId}").asObject(List).body.find{it['name']=='Task'}['id']defuserToFind="<Name of User To Find Here>"defuserSearchRequest=get("/rest/api/3/user/search").queryString("query",userToFind).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].toString()if(userAccountId){defcreateIssue=post('/rest/api/2/issue').header('Content-Type','application/json').body([fields:[summary:'Issue Created By Scriptrunner',reporter:[id:userAccountId],project:[key:projectKey],issuetype:[id:taskType]]]).asString()// Assert the issue was created correcltyassertcreateIssue.status>=200&&createIssue.status<=300}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.