Snippets

Adaptavist Get a User on the Script Console inside of ScriptRunner for Jira Cloud

Updated by Kristian Walker

File snippet.groovy Modified

  • Ignore whitespace
  • Hide word diff
 /*
-* This example script console script shows how to get a user based on a specified username.
+* This example script console script shows how to get a user based on a specified account Id.
 * "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."
 */
 
 // The username to search for
-def userName = '<UsernameHere>'
+def accountID = '<accountIdHere>'
 
 // return the user specified
 def result = get('/rest/api/2/user/')
         .header('Content-Type', 'application/json')
-        .queryString("username", userName)
+        .queryString("accountId", accountID)
         .asObject(Map)
 
 // If the user is found return the details for the user
 if (result.status == 200){
-    return result.body
+    return "The user with the accountId of ${accountID} has the displayName of ${result.body.displayName}"
 } else {
     return "Failed to find user with the name of ${userName} : Status: ${result.status} ${result.body}"
 }
Updated by Kristian Walker

File snippet.groovy Added

  • Ignore whitespace
  • Hide word diff
+/*
+* This example script console script shows how to get a user based on a specified username.
+* "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."
+*/
+
+// The username to search for
+def userName = '<UsernameHere>'
+
+// return the user specified
+def result = get('/rest/api/2/user/')
+        .header('Content-Type', 'application/json')
+        .queryString("username", userName)
+        .asObject(Map)
+
+// If the user is found return the details for the user
+if (result.status == 200){
+    return result.body
+} else {
+    return "Failed to find user with the name of ${userName} : Status: ${result.status} ${result.body}"
+}

File snippet.txt Deleted

  • Ignore whitespace
  • Hide word diff
-/*
-* This example script console script shows how to get a user based on a specified username.
-* "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."
-*/
-
-// The username to search for
-def userName = '<UsernameHere>'
-
-// return the user specified
-def result = get('/rest/api/2/user/')
-        .header('Content-Type', 'application/json')
-        .queryString("username", userName)
-        .asObject(Map)
-
-// If the user is found return the details for the user
-if (result.status == 200){
-    return result.body
-} else {
-    return "Failed to find user with the name of ${userName} : Status: ${result.status} ${result.body}"
-}
Created by Kristian Walker

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+/*
+* This example script console script shows how to get a user based on a specified username.
+* "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."
+*/
+
+// The username to search for
+def userName = '<UsernameHere>'
+
+// return the user specified
+def result = get('/rest/api/2/user/')
+        .header('Content-Type', 'application/json')
+        .queryString("username", userName)
+        .asObject(Map)
+
+// If the user is found return the details for the user
+if (result.status == 200){
+    return result.body
+} else {
+    return "Failed to find user with the name of ${userName} : Status: ${result.status} ${result.body}"
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.