{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":799,"path":"api-reference/server-api-reference/GlideImpersonateAPI.md","title":"GlideImpersonate - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideImpersonate- Global\n\nThe GlideImpersonate API enables administrators to pose as another authenticated user for testing purposes.\n\nUse this API when you need to act as another user so to test functionality within your application. When impersonating another user, the administrator has access to exactly what the impersonated user would have access to in the system, including the same menus and modules.\n\n**Note:** The system records anything the administrator does while impersonating another user as having been done by that user.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## GlideImpersonate - canDebug\\(String userSysId\\)\n\nVerifies whether the specified user can perform debugging on scripts.\n\nIn order for a user to be able to debug scripts, they must be on a developer instance. Debugging is not allowed on production instances.\n\n|Name|Type|Description|\n|----|----|-----------|\n|userSysId|String|sys\\_Id of the user to verify for debugging capability.|\n\n<table id=\"table_wlb_std_t1b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nTrue: User is able to debug the application. False: User is not able to debug the application.\n\n</td></tr></tbody>\n</table>```\nuserDebug: function(userId) {\n  var impUser = new GlideImpersonate();\n  impUser.canDebug(userId);\n }\n```\n\n## GlideImpersonate - canImpersonate\\(String userSysId\\)\n\nVerifies whether the current user can impersonate the specified user.\n\nIf the current user is not assigned the admin role, the user to impersonate is inactive, or there are other issues with impersonating the specified user, the method returns \"false\" and the user cannot be impersonated.\n\n|Name|Type|Description|\n|----|----|-----------|\n|userSysId|String|sys\\_Id of the user to impersonate|\n\n<table id=\"table_g2t_w4d_t1b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the current user can impersonate the specified user.Possible values:\n\n-   true: Current user can impersonate the specified user.\n-   false: Current user cannot impersonate the specified user.\n\n</td></tr></tbody>\n</table>```\nfunction onlineImpersonate(userSysId) {\n  if (!GlideImpersonate().canImpersonate(userSysId)){\n    gs.addInfoMessage(\"No access to impersonate \" + userSysId);\n  } else {\n    GlideImpersonate().impersonate(userSysId);\n  }\n  return;\n}\n```\n\n## GlideImpersonate - impersonate\\(String userSysId\\)\n\nSets the user ID for the current administrator to the passed-in user ID, enabling the administrator to act as that user.\n\nWhen impersonating another user, the administrator has access to exactly what the impersonated user would have access to in the system, including the same menus and modules. Only use this method when testing functionality in an application. Ensure that once you are finished impersonating a user that you call the method again with the administrator sys\\_Id to stop the impersonation.\n\n|Name|Type|Description|\n|----|----|-----------|\n|userSysId|String|Sys\\_id of the user to impersonate.|\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the user that was logged in prior to the impersonation request.|\n\nThe following example shows how to get the current user object.\n\n```\nvar user = gs.getUserDisplayName();\ngs.print (\"The current user display name is: \" + user);\n\nvar impUser = new GlideImpersonate();\nimpUser.impersonate(\"62826bf03710200044e0bfc8bcbe5df1\");\nvar user = gs.getUserDisplayName();\ngs.print (\"The impersonated user display name is: \" + user);\n```\n\nOutput:\n\n```\nThe current user display name is: System Administrator\nThe impersonated user display name is: Abel Tuter\n```\n\n## GlideImpersonate - isImpersonating\\(\\)\n\nDetermines whether the current user is impersonating another user.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_mrd_nwd_t1b\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nTrue: User is currently impersonating another user.False: User is not currently impersonating another user.\n\n</td></tr></tbody>\n</table>```\nfunction abortOnImpersonate() {\n    if (GlideImpersonate().isImpersonating()){\n  current.setAbortAction(true);\n  gs.addInfoMessage(\"Transaction canceled due to Impersonation\");\n    }\n    return;\n}\n```\n\n"}}