
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 11:25 AM
Hi folks ,
I am bit new to servicenow scripting , I am trying to write ui policies by using client scripts .
1)Could anyone explain where exactly we use client side functions like g_form and g_user. ?
2)what is exactly difference between g_user.hasRole , g_user.hasRoles() , , g_user.hasRoleExactly() , g_user.hasRoleFromList and in which scenarios we use these methods .
ThankYou In Advance .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 12:16 PM
1)Could anyone explain where exactly we use client side functions like g_form and g_user. ?
g_form :
GlideForm.js is the Javascript class used to customize forms.
g_form is a global object in the GlideForm class.
GlideForm.js and g_form are only used on the client (for instance, the web browser).
These methods are used to make custom changes to the form view of records. All validation of examples was done using Client Scripts.
Some of these methods can also be used in other client scripts (such as Catalog Client Scripts or Wizard Client Scripts), but must first be tested to determine whether they will work as expected.
g_user :
g_user is a global object in GlideUser (the Javascript class).
g_user
- can only be used in Client Scripts.
- contains name and role information about the current user.
- is typically used in Client Scripts and UI Policies but is also found in UI Actions which run on the client.
- cannot be used in Business Rules or UI Actions which run on the server.
- avoids the need for much slower user queries (for example, GlideRecord queries to get user information)
Session information about the current user and current user roles is contained in the client (for example, web browser). All methods below [except getClientData()] access the session information that is available by default. getClientData() requires setup on the server and use of putClientData() to make session information available.
2)what is exactly difference between g_user.hasRole , g_user.hasRoles() , , g_user.hasRoleExactly() ,and in which scenarios we use these methods ?
g_user.hasRole() :
True if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role.
ex: g_user.hasRole('itil')
g_user.hasRoles()
True if the current user has at least one role specified, false otherwise.
ex: g_user.hasRoles('itil','admin')
g_user.hasRoleExactly()
True if the current user has the exact role specified, false otherwise, regardless of 'admin' role.
ex:g_user.hasRoleExactly('itil');
formore information refer servicenow wiki
GlideForm (g form) - ServiceNow Wiki
GlideUser (g user) - ServiceNow Wiki
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
Thanks & Regards
Haseena
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 11:33 AM
everything you want to know: https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 12:16 PM
1)Could anyone explain where exactly we use client side functions like g_form and g_user. ?
g_form :
GlideForm.js is the Javascript class used to customize forms.
g_form is a global object in the GlideForm class.
GlideForm.js and g_form are only used on the client (for instance, the web browser).
These methods are used to make custom changes to the form view of records. All validation of examples was done using Client Scripts.
Some of these methods can also be used in other client scripts (such as Catalog Client Scripts or Wizard Client Scripts), but must first be tested to determine whether they will work as expected.
g_user :
g_user is a global object in GlideUser (the Javascript class).
g_user
- can only be used in Client Scripts.
- contains name and role information about the current user.
- is typically used in Client Scripts and UI Policies but is also found in UI Actions which run on the client.
- cannot be used in Business Rules or UI Actions which run on the server.
- avoids the need for much slower user queries (for example, GlideRecord queries to get user information)
Session information about the current user and current user roles is contained in the client (for example, web browser). All methods below [except getClientData()] access the session information that is available by default. getClientData() requires setup on the server and use of putClientData() to make session information available.
2)what is exactly difference between g_user.hasRole , g_user.hasRoles() , , g_user.hasRoleExactly() ,and in which scenarios we use these methods ?
g_user.hasRole() :
True if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role.
ex: g_user.hasRole('itil')
g_user.hasRoles()
True if the current user has at least one role specified, false otherwise.
ex: g_user.hasRoles('itil','admin')
g_user.hasRoleExactly()
True if the current user has the exact role specified, false otherwise, regardless of 'admin' role.
ex:g_user.hasRoleExactly('itil');
formore information refer servicenow wiki
GlideForm (g form) - ServiceNow Wiki
GlideUser (g user) - ServiceNow Wiki
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
Thanks & Regards
Haseena
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2020 12:23 AM
Check out this video, it will clear all your doubts and help you to understand Client Script queries in details.
Link: https://www.youtube.com/watch?v=Wj8ZAWtTBqo&ab_channel=ServiceNowHelpdesk
It help you to understand below points.
- UI policy and Client script
- why client script run first in service now?.
- Which rule execute first client Scripts or UI polices?
- g_user and g_form tips
- Difference between client script and script include (server).
- Scenario based implementation
- Understanding below
- onLoad()
- onChange()
- onSubmit()
- onCellEdit()
Please mark reply as Helpful/Correct, if applicable. Thanks!!