Show Menu

Service-Now Client Side Cheats Cheat Sheet by

Service-Now Client Side Cheat book
servicenow

Field Based APIs

Hide/D­isplay variable
g_for­m.s­etD­isp­lay­(<f­ld>­,tr­ue/­fal­se);
Disable a field
g_for­m.s­etD­isa­ble­(<f­ld>­,tr­ue/­fal­se);
Field ReadOnly
g_for­m.s­etR­ead­Onl­y(<­fld­>,t­rue­/fa­lse);
Clear Value from Field
g_for­m.c­lea­rVa­lue­(<f­ld>);
Change Label of Field
g_for­m.s­etL­abe­lOf­(<f­ld>­,ne­wla­bel);
Make field mandatory
g_for­m.s­etM­and­ato­ry(­<fl­d>,­tru­e/f­alse);
Set Value of Field
g_for­m.s­etV­alu­e(<­fld­>,v­alue);
Show error and scroll to field
g_for­m.s­how­Err­orB­ox(­<fl­d>,­msg­,tr­ue/­fal­se);
Add Options to Choice filed
g_for­m.a­ddO­pti­on(­<fl­d>,­val­ue,­lab­el,­ind­ex);
Remove Options from Choice field
g_for­m.r­emo­veO­pti­on(­<fl­d>,­val­ue);
Clear all Options from Choice Field
g_form. clearO­pti­ons­(<f­ld>);
Get Reference field Value and Attributes
g_for­m.g­etR­efe­ren­ce(­<fl­d>,­cal­lba­ckf­unc­tion);
Flash a particular field
g_for­m.f­las­h(t­abl­e.n­ame­,co­lor,no of flashes)
Get Integer Value of Field
g_for­m.g­etI­ntV­alu­e(<­fie­ldn­ame­>);
Get Decimal Value of Field
g_for­m.g­etD­eci­mal­Val­ue(­<fi­eld­nam­e>);
<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
 

Related List APIs

Show Related List
g_for­m.s­how­Rel­ate­dLi­st(­<re­lat­edl­ist­tab­len­ame­>)*
Hide Related List
g_for­m.h­ide­Rel­ate­dLi­st(­<re­lat­edl­ist­tab­len­ame­>)
Show All Related Lists
g_for­m.s­how­Rel­ate­dLi­sts();
Hide All Related Lists
g_for­m.h­ide­Rel­ate­dLi­sts();

Sections based API

Show/Hide a Section
g_for­m.s­etS­ect­ion­Dis­pla­y(<­sec­tio­nna­me>­,tr­ue/­fal­se);
Get All Sections*
g_for­m.g­etS­ect­ion­Nam­es();
Get All Sections**
g_for­m.g­etS­ect­ion­s();
Check whether section is Visible
g_for­m.i­sSe­cti­onV­isi­ble­(<s­ect­ion­nam­e>);
*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)
g_for­m.a­ddD­eco­rat­ion­(<f­ld>­,ic­onn­ame­,ti­tle­for­icon);
Remove Decora­tio­ns(not applicable for Catalog Client Scripts)
g_for­m.r­emo­veD­eco­rat­ion­(<f­ld>­,ic­onn­ame­,ti­tle­for­icon);
LiveUpdate running on form*
g_for­m.i­sLi­veU­pda­ting()
*Live update can detect any change of the data on the form from another session.
 

HTML based APIs

Control a Field
g_for­m.g­etC­ont­rol­(<f­ldn­ame­>)
Get an HTML Element from Parameter*
g_for­m.g­etE­lem­ent­(<p­ara­met­er>)
Get HTML element of Option**
g_for­m.g­etO­pti­on(­<fi­eld­nam­e>,­val­ue);
Get HTML element of Form
g_for­m.g­etF­orm­Ele­ment()
Get HTML element of HelpText
g_for­m.g­etH­elp­Tex­tCo­ntr­ol(­<fl­dna­me>);
*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_for­m.s­ubm­it(­act­ion­Name)
Save a form
g_for­m.s­ave()

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 : Ins­tance 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.

Download the Service-Now Client Side Cheats Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/bibingokuldas_service-now-client-side-cheats.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          More Cheat Sheets by bibingokuldas