CAD practice question 14 of 35

Which one of the following is true for this script fragment? g_user.hasRole(,x_my_app_user');

Full set: 264 questions
Answer options
A: The method returns true if the currently logged in user has the x_my_app_user role or the admin role Correct answer
B: The method returns false only if the currently logged in user has the x_my_app_user role
C: There is no g_user.hasRole() method
D: The method returns true only if the currently logged in user has the x_my_app_user role
Correct Answer:
A. The method returns true if the currently logged in user has the x_my_app_user role or the admin role
Explanation

guser represents the GlideUser client-side object. Its hasRole(String role) method “returns true if the currently logged-in user possesses the specified role OR is an administrator.” Therefore, the call guser.hasRole('xmyappuser') evaluates to true when the user either explicitly holds the xmyappuser role or holds the admin role, making option A the only correct statement.

Why Incorrect

B. Method returns false when the user lacks BOTH the role and admin; having the role makes it true, so statement is inaccurate.
C. guser.hasRole() is an officially documented method; it does exist.
D. Ignores the documented admin override, so it is incomplete/incorrect.

References

1. ServiceNow Product Documentation – “GlideUser (guser) API”, section “hasRole(String role)”, Orlando-Tokyo versions: “Returns true if the user has the role or is an administrator.”

URL: https://developer.servicenow.com/dev.do#!/reference/api/rome/client/cGlideUserAPI#guserhasRole

2. ServiceNow Product Documentation – “GlideSystem (gs) API”, section “hasRole(String role)”, confirms identical admin override behavior (supports consistency across client/server).

URL: https://developer.servicenow.com/dev.do#!/reference/api/rome/serverlegacy/cGlideSystemAPI#hasRole

Scroll to Top