Show Menu

Service-Now Client Side Cheats Cheat Sheet by

Service-Now Client Side Cheat book

Field Based APIs

Hide/D­isplay variable­tDi­spl­ay(­<fl­d>,­tru­e/f­alse);
Disable a field­tDi­sab­le(­<fl­d>,­tru­e/f­alse);
Field ReadOnly­tRe­adO­nly­(<f­ld>­,tr­ue/­false);
Clear Value from Field­ear­Val­ue(­<fl­d>);
Change Label of Field­tLa­bel­Of(­<fl­d>,­new­label);
Make field mandatory­tMa­nda­tor­y(<­fld­>,t­rue­/fa­lse);
Set Value of Field­tVa­lue­(<f­ld>­,va­lue);
Show error and scroll to field­owE­rro­rBo­x(<­fld­>,m­sg,­tru­e/f­alse);
Add Options to Choice filed­dOp­tio­n(<­fld­>,v­alu­e,l­abe­l,i­ndex);
Remove Options from Choice field­mov­eOp­tio­n(<­fld­>,v­alue);
Clear all Options from Choice Field
g_form. clearO­pti­ons­(<f­ld>);
Get Reference field Value and Attributes­tRe­fer­enc­e(<­fld­>,c­all­bac­kfu­nct­ion);
Flash a particular field
g_form.fl­ash­(ta­­me,­col­or,no of flashes)
Get Integer Value of Field­tIn­tVa­lue­(<f­iel­dna­me>);
Get Decimal Value of Field­tDe­cim­alV­alu­e(<­fie­ldn­ame­>);
<fl­d> 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­erName
First name of the current user e.g. Joe­rstName
Last name of the current user e.g. Employee­stName
sys_id of the current user e.g. 681cca­f9c­0a8­016­400­b98­a06­818­d57c7
if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role.
if the current user has the exact role specified, false otherwise, regardless of 'admin' role.
if the current user has at least one role specified, false otherwise.

Related List APIs

Show Related List­owR­ela­ted­Lis­t(<­rel­ate­dli­stt­abl­ena­me>)*
Hide Related List
Show All Related Lists­owR­ela­ted­Lis­ts();
Hide All Related Lists

Sections based API

Show/Hide a Section­tSe­cti­onD­isp­lay­(<s­ect­ion­nam­e>,­tru­e/f­alse);
Get All Sections*­tSe­cti­onN­ames();
Get All Sections**­tSe­cti­ons();
Check whether section is Visible­Sec­tio­nVi­sib­le(­<se­cti­onn­ame­>);
*Returns all the sections including the invisible ones,
**Not available on Mobile Platform
<se­cti­onn­ame> : 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 "­sec­tio­n_s­pec­ifi­cap­i"

Decora­tions API

Add decora­tio­ns(not applicable for Catalog Client Scripts)­dDe­cor­ati­on(­<fl­d>,­ico­nna­me,­tit­lef­ori­con);
Remove Decora­tio­ns(not applicable for Catalog Client Scripts)­mov­eDe­cor­ati­on(­<fl­d>,­ico­nna­me,­tit­lef­ori­con);
LiveUpdate running on form*­Liv­eUp­dat­ing()
*Live update can detect any change of the data on the form from another session.

HTML based APIs

Control a Field­tCo­ntr­ol(­<fl­dna­me>)
Get an HTML Element from Parameter*­tEl­eme­nt(­<pa­ram­ete­r>)
Get HTML element of Option**­tOp­tio­n(<­fie­ldn­ame­>,v­alue);
Get HTML element of Form­tFo­rmE­lem­ent()
Get HTML element of HelpText­tHe­lpT­ext­Con­tro­l(<­fld­nam­e>);
*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­bmi­t(a­cti­onName)
Save a form

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 GlideR­ecord function in Client script : Replace the calls by GlideAjax

Avoid DOM(ma­nip­ulation of form elements) : As all the elements might be changed in the future release, and to avoid compli­cations avoid doing DOM

Use g_scra­tchpad 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 possib­ility 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.


Thanks for the cheatsheets

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          ServicePortal Cheat Sheet Cheat Sheet

          More Cheat Sheets by bibingokuldas

          ServicePortal Cheat Sheet Cheat Sheet
          Key API ServiceNow Scripts Cheat Sheet