nerdexam
ServiceNow

CAD · Question #76

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

The correct answer is A. The method returns true if the currently logged in user has the x_my_app_user role or the admin. The statement that is true for this script fragment is that the method returns true if the currently logged in user has the x_my_app_user role or the admin role. The g_user.hasRole() method is a client-side method that checks whether the current user has a specified role or set…

Submitted by diego_uy· Apr 18, 2026Security and Restricting Access

Question

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

Options

  • AThe method returns true if the currently logged in user has the x_my_app_user role or the admin
  • BThe method returns false only if the currently logged in user has the x_my_app_user role
  • CThere is no g_user.hasRole() method
  • DThe method returns true only if the currently logged in user has the x_my_app_user role

How the community answered

(46 responses)
  • A
    87% (40)
  • B
    7% (3)
  • C
    4% (2)
  • D
    2% (1)

Explanation

The statement that is true for this script fragment is that the method returns true if the currently logged in user has the x_my_app_user role or the admin role. The g_user.hasRole() method is a client-side method that checks whether the current user has a specified role or set of roles. If no role is specified, it returns true if the user has any role. If one or more roles are specified, it returns true if the user has any one of the specified roles. However, this method always returns true if the user has the admin role, regardless of the role parameter. Therefore, in this case, the method returns true if the user has either the x_my_app_user role or the admin role.

Topics

#Client-side scripting#g_user API#Role management#Access control

Community Discussion

No community discussion yet for this question.

Full CAD Practice