Field Based APIs
Hide/Display variable |
g_form.setDisplay(<fld>,true/false); |
Disable a field |
g_form.setDisable(<fld>,true/false); |
Field ReadOnly |
g_form.setReadOnly(<fld>,true/false); |
Clear Value from Field |
g_form.clearValue(<fld>); |
Change Label of Field |
g_form.setLabelOf(<fld>,newlabel); |
Make field mandatory |
g_form.setMandatory(<fld>,true/false); |
Set Value of Field |
g_form.setValue(<fld>,value); |
Show error and scroll to field |
g_form.showErrorBox(<fld>,msg,true/false); |
Add Options to Choice filed |
g_form.addOption(<fld>,value,label,index); |
Remove Options from Choice field |
g_form.removeOption(<fld>,value); |
Clear all Options from Choice Field |
g_form. clearOptions(<fld>); |
Get Reference field Value and Attributes |
g_form.getReference(<fld>,callbackfunction); |
Flash a particular field |
g_form.flash(table.name,color,no of flashes) |
Get Integer Value of Field |
g_form.getIntValue(<fieldname>); |
Get Decimal Value of Field |
g_form.getDecimalValue(<fieldname>); |
<fld> Represent the field name on which the function has to work
value - is something what you have to set.
true / false - true is for enabling, false is for disable
User Objects
User name of the current user e.g. employee |
g_user.userName |
First name of the current user e.g. Joe |
g_user.firstName |
Last name of the current user e.g. Employee |
g_user.lastName |
sys_id of the current user e.g. 681ccaf9c0a8016400b98a06818d57c7 |
g_user.userID |
if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role. |
g_user.hasRole(<rolename>) |
if the current user has the exact role specified, false otherwise, regardless of 'admin' role. |
g_user.hasRoleExactly(<rolename>) |
if the current user has at least one role specified, false otherwise. |
g_user.hasRoles(<rolename1>,<rolename2>) |
|
|
Related List APIs
Show Related List |
g_form.showRelatedList(<relatedlisttablename>)* |
Hide Related List |
g_form.hideRelatedList(<relatedlisttablename>) |
Show All Related Lists |
g_form.showRelatedLists(); |
Hide All Related Lists |
g_form.hideRelatedLists(); |
Sections based API
Show/Hide a Section |
g_form.setSectionDisplay(<sectionname>,true/false); |
Get All Sections* |
g_form.getSectionNames(); |
Get All Sections** |
g_form.getSections(); |
Check whether section is Visible |
g_form.isSectionVisible(<sectionname>); |
*Returns all the sections including the invisible ones,
**Not available on Mobile Platform
<sectionname> : the section name in ServiceNow is created by replacing the 1st space by "_" and trimming rest of the spaces, for ex :if a section on form is created as "Section Specific API" then section name is "section_specificapi"
Decorations API
Add decorations(not applicable for Catalog Client Scripts) |
g_form.addDecoration(<fld>,iconname,titleforicon); |
Remove Decorations(not applicable for Catalog Client Scripts) |
g_form.removeDecoration(<fld>,iconname,titleforicon); |
LiveUpdate running on form* |
g_form.isLiveUpdating() |
*Live update can detect any change of the data on the form from another session.
|
|
HTML based APIs
Control a Field |
g_form.getControl(<fldname>) |
Get an HTML Element from Parameter* |
g_form.getElement(<parameter>) |
Get HTML element of Option** |
g_form.getOption(<fieldname>,value); |
Get HTML element of Form |
g_form.getFormElement() |
Get HTML element of HelpText |
g_form.getHelpTextControl(<fldname>); |
*Not available in the Mobile and Service Portal
**The method will not work on readonly fields, and if the field is not present on the form it will result in null.
Action Specific API
Submit a form |
g_form.submit(actionName) |
Save a form |
g_form.save() |
Best Practices Client Scripting
Use UI policies instead of Client scripts : For basics like making field readonly, mandatory best practice suggests to use UI Policies.
Always use isLoading check when in onChange Client Scripts : All the onChange client script will get executed onLoad as well, always check whether the form is loading by isLoading function
Avoid Using GlideRecord function in Client script : Replace the calls by GlideAjax
Avoid DOM(manipulation of form elements) : As all the elements might be changed in the future release, and to avoid complications avoid doing DOM
Use g_scratchpad to minimise server calls : When working with lot of data write a Display Business Rule and make the data available to Client Side
When using JQuery in Client Scripts : Instance before london, has no possibility of isolating a JQuery Script, but instances in London and above has a strict client mode, where methods like window, eval would only work if isolation is turned on. |
|
Created By
https://bibingokuldas.com
Metadata
Favourited By
Comments
kea235, 19:58 11 Oct 20
Thanks for the cheatsheets
Add a Comment
Related Cheat Sheets
More Cheat Sheets by bibingokuldas