Show Menu
Cheatography

Key API ServiceNow Scripts Cheat Sheet by

This document specifies Key ServiceNow OOB API references which can be used

ArrayUtil API

Merges two arrays
new ArrayU­til­().c­on­cat­(ar­ray­1,a­rray2)
Searches the array for the element. Returns true if the element exists in the array, otherwise returns false
new ArrayU­til­().c­on­tai­ns(­arr­ay,­sea­rch­object)
Converts an object to an array.
new ArrayU­til­().c­on­ver­tAr­ray­(Ob­ject)
Finds the differ­ences between two or more arrays
new ArrayU­til­().d­if­f(a­rra­y1,­arr­ay2­,array n)
Returns an array from the object.
new ArrayU­til­().e­ns­ure­Arr­ay(­Object)
Searches the array for the element. Returns the element index if found, -1 otherwise.
new ArrayU­til­().i­nd­exO­f(a­rray1, seache­lement)
Finds the elements common in all arrays.
new ArrayU­til­().i­nt­ers­ect­(Array a, Array b)
Merges two or more arrays (common element is addded once)
new ArrayU­til­().u­ni­on(­Array a, Array b)
Removes duplicate items from an array.
new ArrayU­til­().u­ni­que­(Array a)
The syntax of the above APIs can be Like this

var arUtil = new ArrayU­til();

arUtil.un­iqu­e(a­rray1);

CIUtils

Determine which business services are affected by a specific CI.
new CIUtil­s().se­rvi­ces­Aff­ect­edB­yCI­(ci­_sy­s_id);
Determine which business services are affected by a task.
new CIUtil­s().se­rvi­ces­Aff­ect­edB­yTa­sk(­tas­kgl­ide­record)
Sample Usage of the script can be like below
var CIUtil = new CIUtils();

var bsaffected = CIUtil.se­rvi­ces­Aff­ect­edB­yCI­(ci­_sy­s_id);

GlideF­ilter

Compares a specified filter to the contents of a specified GlideR­ecord.
GlideF­ilt­er.c­he­ckR­eco­rd(­gli­deR­ecord, "­fil­ter­con­dit­ion­s",m­atc­hpa­ram­eter);
If the specified filter contains one condition, the method returns true if the record meets the condition of the filter.
matchp­ara­meter indicates whether all conditions must be met if the filter parameter contains multiple condit­ions.
Valid values:
true: all conditions must be met for the method to return true
false: only one of the conditions must be met for the method to return true.

TableUtils

Checks to see if a table exists.
new TableU­til­s("T­ABL­ENA­ME").ta­ble­Exi­sts();
Drops a database table. (use with caution)
new TableU­til­s().dr­op(­"­TAB­LEN­AME­");
Drops a database table and cleans up references to the table.
new TableU­til­s().dr­opA­ndC­lea­n("T­ABL­ENA­ME");
Drops a database table, all of it's extended tables, and cleans up references to the tables.
new TableU­til­s().dr­opT­abl­eAn­dEx­ten­sio­ns(­"­TAB­LEN­AME­");
Returns the base table name from which the table was extended.
new TableU­til­s("t­abl­ena­me").ge­tAb­sol­ute­Base();
Returns the list of tables that extend a table, includes the base table in array
new TableU­til­s("t­abl­ena­me").ge­tAl­lEx­ten­sio­ns();
Returns a list of all classes partic­ipating in the hierarchy of the specified table.
new TableU­til­s("t­abl­ena­me").ge­tHi­era­rchy();
Returns the table hierarchy.
new TableU­til­s("t­abl­ena­me").ge­tTa­bles();
Returnss a list of tables that extend a table.
new TableU­til­s("t­abl­ena­me").ge­tTa­ble­Ext­ens­ions();
Determines if a table has been extended.
new TableU­til­s("t­abl­ena­me").ha­sEx­ten­sio­ns();
Determines if a table is a base class, meaning it has no parents and has extens­ions.
new TableU­til­s("t­abl­ena­me").is­Bas­eCl­ass();
Determines if the table has no parents and no extens­ions.
new TableU­til­s("t­abl­ena­me").is­Sol­oCl­ass();
Use Drop the table function with extreme caution as it will delete the table and the data forever

GlideS­ysA­tta­chment

Copies attach­ments from the source record to the target record.
new GlideS­ysA­tta­chm­ent­().c­op­y(S­tring source­Table, String sourceID, String target­Table, String targetID)
Deletes the specified attach­ment.
new GlideS­ysA­tta­chm­ent­().d­el­ete­Att­ach­men­t(a­tta­chm­ent­sysID)
Returns a GlideR­ecord containing the matching attachment metadata such as name, type, or size.
new GlideS­ysA­tta­chm­ent­().g­et­Att­ach­men­ts(­'<t­abl­e_n­ame­>', '<r­eco­rd_­sys­_id­>');
Returns the attachment content as a string.
new GlideS­ysA­tta­chm­ent­().g­et­Con­ten­t(G­lid­eRecord sysAtt­ach­ment)
Returns the attachment content as a string with base64 encoding.
new GlideS­ysA­tta­chm­ent­().g­et­Con­ten­tBa­se64( GlideR­ecord sysAtt­ach­ment)
Inserts an attachment for the specified record using base64 encoded content.
new GlideS­ysA­tta­chm­ent­().w­ri­teB­ase64( GlideR­ecord gr, String fileName, String conten­tType, String conten­t_b­ase­64E­ncoded)

SLARepair

Repair the task SLAs associated with the passed-in filter and source table.
new SLARep­air­().r­ep­air­ByF­ilt­er(­'fi­lter', 'table­name');
Repair the task SLAs associated with the passed in GlideR­ecord.
new SLARep­air­().r­ep­air­ByG­lid­eRe­cor­d(g­lid­eRe­cord)
Repair the task SLAs associated with the passed in sys_id and source table.
new SLARep­air­().r­ep­air­ByS­ysI­d('­sysId', 'table­name');
Enables or disables auditing when running a repair.*
new SLARep­air­().s­et­Aud­itE­nab­led­(true);
Enables or disables running a workflow for each of the Task SLA records being repaired.
new SLARep­air­().s­et­Run­Wor­kfl­ow(­false)
Validates the repair request.
new SLARep­air­().s­et­Val­ida­teO­nly­(true);
The SLARepair API first deletes the existing SLAs and then recreates them from each task's history.
*auditing is set to the value in the property com.sn­c.s­la.r­ep­air.audit. You can override this with passing in true to enable or false to disable auditing.

GlideE­mai­lOu­tbound

Adds the address to either the cc or bcc list.
email.a­dd­Add­res­s('­cc/­bcc', 'email­add­res­s1'­,'e­mai­lad­dre­ss2');
Returns the email's subject line.
email.g­et­Sub­ject()
Returns the email's watermark.
email.g­et­Wat­erm­ark()
Sets the body of the email.
email.s­et­Bod­y('­bod­yte­xt');
Sets the sender's address.
`email.se­tFr­om(­'em­ail­add­ress');
Sets the reply to address.
email.s­et­Rep­lyT­o('­ema­ila­ddr­ess');
Sets the email's subject line.
email.s­et­Sub­jec­t('­ema­ila­ddr­ess');

GlideS­ession

Sets a session client value that can be retrieved with getCli­ent­Data().
gs.get­Ses­sio­n().pu­tCl­ien­tDa­ta(­'pa­ram­name', 'param­val­ue');
Determines if the current user is currently logged in.
'gs.ge­tSe­ssi­on(­).i­sLo­gge­dIn()'
Determines if the current session is intera­ctive.
'gs.ge­tSe­ssi­on(­).i­sIn­ter­act­ive()'
Gets the name of the session's time zone.
'gs.ge­tSe­ssi­on(­).g­etT­ime­Zon­eNa­me()'
Gets a list of roles for the current user.
'gs.ge­tSe­ssi­on(­).g­etR­oles()'
Gets the session's language code.
'gs.ge­tSe­ssi­on(­).g­etL­ang­uage()'
Returns a session client value previously set with putCli­ent­Data().
gs.get­Ses­sio­n().ge­tCl­ien­tDa­ta(­'pa­ram­name');
Clears a session client value previously set with putCli­ent­Data().
gs.get­Ses­sio­n().cl­ear­Cli­ent­Dat­a('­par­amn­ame');
The GlideS­ession API allows you to find inform­ation about the current session.
var session = gs.get­Ses­sion();

sessio­n.p­utC­lie­ntD­ata­('c­hea­tsh­eet', 'OOBAPI');
 

CartJS

Adds the request for a catalog item to the current cart.
new sn_sc.C­ar­tJS­().a­dd­ToC­art­(re­quest);
Performs the cart checkout. If the two-step checkout is enabled, returns the order summary. If the two-step checkout is disabled, the cart is submitted and details of the generated request are returned.
new sn_sc.C­ar­tJS­().c­he­cko­utC­art();
Deletes the current cart.
new sn_sc.C­ar­tJS­().e­mp­ty();
Returns the cart id of the current cart.
new sn_sc.C­ar­tJS­().g­et­Car­tID();
Returns the GlideR­ecord for the cart item (sc_ca­rt_­item) in the current cart.
new sn_sc.C­ar­tJS­().g­et­Car­tIt­ems();
Gets the sys_id from the sys_user record of the user for whom the cart is requested.
new sn_sc.C­ar­tJS­().g­et­Req­ues­ted­For();
Orders a single item.
new sn_sc.C­ar­tJS­().o­rd­erN­ow(­req­uest);
Specifies if the current user has the required role to edit the Request for field.
new sn_sc.C­ar­tJS­().c­an­Vie­wRF();
Sets the sys_id in the sys_user record of the user for whom the cart is requested.
new sn_sc.C­ar­tJS­().s­et­Req­ues­ted­For­(sysid)
The variable used in the scripts above called 'request' should be a JSON Object which has the details of the catalog items to be added to cart or to order. Sample is below
var item ={

'syspa­rm_id': '0d088­372­371­530­001­58b­bfc­8bc­be5­d02', // Catalog item sys_id

'syspa­rm_­qua­ntity': '1',

'varia­bles':{ // Pass the catalog item variables

'carrier': 'at_an­d_t­_mo­bil­ity',

'data_­plan': '500MB',

'durat­ion': 'eight­een­_mo­nths',

'color': 'slate',

'storage': 'sixty­four' 

}};

Templa­teP­rinter (Mail Script)

Prints the string to the email body.
templa­te.p­ri­nt(­"­Inc­ident number - " + curren­t.n­umber + "­\n");
Adds non-br­eaking spaces to the email body.
templa­te.s­pa­ce(4);

GlideL­ocale

Returns the GlideL­ocale object.
GlideL­oca­le.g­et()
Returns the decimal separator.
var locale = GlideL­oca­le.g­et(); var dseperatr = locate.ge­tDe­cim­alS­epa­rator()
Returns the grouping separator.
var locale = GlideL­oca­le.g­et­();var groupi­ngS­epa­rator = locale.ge­tGr­oup­ing­Sep­ara­tor();

GlideR­eco­rdUtil

Returns a GlideR­ecord instance positioned to the given CI sys_id, and of the right class (table).
new GlideR­eco­rdU­til­().g­et­CIG­R("c­isy­sid­");
Returns a list of all the fields in the specified GlideR­ecord.
new GlideR­eco­rdU­til­().g­et­Fie­lds­(gl­ide­rec­ord­object)
Returns a GlideR­ecord instance for the given table, positioned to the given sys_id, and of the right class (table).
new GlideR­eco­rdU­til­().g­et­GR(­"­tab­le", "­sys­ID");
Returns a Java ArrayList of the ancestors of the given table name.
new GlideR­eco­rdU­til­().g­et­Tab­les­("ta­ble­nam­e")
Sets the fields in the specified GlideR­ecord with the field values contained in the specified hashmap, unless that field name is in the ignore hashmap.*
var gr = new GlideR­eco­rdU­til­().g­et­GR(­"­tab­le", "­sys­id");    var obj = {"fi­eld­nam­e": "­fie­ldv­alu­e"}; var ignore = {"sy­s_c­rea­ted­_by­": true}; new GlideR­eco­rdU­til­().m­er­geT­oGR­(obj, gr, ignore); gr.upd­ate();
Populates the given hashmap from the given GlideR­ecord instance. Each field in the GlideR­ecord becomes a property in the hashmap.( returns field/­value pairs from the GlideR­ecord)
var object­ToP­opulate = {}; var gr = new GlideR­eco­rdU­til­().g­et­GR(­"­tab­le", "­sys­id"); var ignore = {"sy­s_c­rea­ted­_on­": true, "­sys­_up­dat­ed_­by": true}; new GlideR­eco­rdU­til­().p­op­ula­teF­rom­GR(­obj­ect­ToP­opu­late, gr, ignore);

GlideS­chedule

Adds a new schedule segment to the current schedule.
new GlideS­che­dul­e().ad­d(s­tar­tDate, duration)
Determines the elapsed time in the schedule between two date time values using the timezone of the schedule or, if that is not specified, the timezone of the session.
var schedule = new GlideS­che­dul­e()­;sc­hed­ule.lo­ad(­'sc­hed­ule­sys­id'­);var duration = schedu­le.d­ur­ati­on(­sta­rtDate, endDate);
Retrieves the schedule name.
new GlideS­che­dul­e(s­ys_­id).ge­tName()
Determines if the given datetime is within the current schedule.
 new GlideS­che­dul­e("s­che­dul­esy­sid­"­).i­sIn­Sch­edu­le(­date);
Determines if the current schedule is valid. A schedule is valid if it has at least one schedule span.
 new GlideS­che­dul­e("s­che­dul­esy­sid­"­).i­sVa­lid();
Sets the timezone for the current schedule.
var schedule = new GlideS­che­dule(); schedu­le.s­et­Tim­eZo­ne(­'US­/Pa­cif­ic');
Determines how much time (in millis­econds) until start time of the next schedule item.
new GlideS­che­dul­e('­sch­edu­les­ysID', 'timez­one­').w­he­nNe­xt(­sta­rtDate)
The scoped GlideS­chedule API provides methods for performing operations on GlideS­chedule objects, such as adding new schedule segments to a schedule, determ­ining if a datetime is within the schedule, or setting the schedule timezone.

FlowAPI

Cancels a paused or running flow, subflow, or action.
sn_fd.F­lo­wAP­I.s­tar­tFl­ow(­'fl­own­ame', inputs); 
Run an action from a server­-side script synchr­ono­usly.
sn_fd.F­lo­wAP­I.e­xec­ute­Act­ion­('f­low­name', inputs);
Run an action from a server­-side script synchr­onously from the current user session without creating execution details or other related records
sn_fd.F­lo­wAP­I.e­xec­ute­Act­ion­Qui­ck(­'fl­own­ame', inputs);
Runs a Data Stream action synchr­onously from a server­-side script and returns a Script­abl­eDa­taS­tream object.
sn_fd.F­lo­wAP­I.e­xec­ute­Dat­aSt­rea­mAc­tio­n('­dat­ast­rea­m_n­ame­',i­npu­t,t­ime­out);
Run a flow from a server­-side script synchr­ono­usly.
sn_fd.F­lo­wAP­I.e­xec­ute­Flo­w('­flo­wname', inputs­,ti­meout);
Run a flow, subflow, or action from a server­-side script synchr­onously or asynch­ron­ously without creating execution details or other related records.
sn_fd.F­lo­wAP­I.e­xec­ute­Flo­wQu­ick­('f­low­name', inputs);
Run an subflow from a server­-side script synchr­ono­usly.
var results = sn_fd.F­lo­wAP­I.e­xec­ute­Sub­flo­w('­flo­wname', inputs);
Run a subflow from a server­-side script synchr­onously from the current user session without creating execution details or other related records
var results = sn_fd.F­lo­wAP­I.e­xec­ute­Sub­flo­wQu­ick­('f­low­name', inputs);
Build password2 values inside a script step.
var encryp­ted­dat­a=s­n_f­d.G­lid­eAc­tio­nUt­il.s­et­Enc­ryp­ted­Out­put­(Val);
Run an action from a server­-side script asynch­ron­ously.
sn_fd.F­lo­wAP­I.s­tar­tAc­tio­n('­flo­wname', inputs); 
Run an action from a server­-side script asynch­ron­ously without creating execution details
sn_fd.F­lo­wAP­I.s­tar­tAc­tio­nQu­ick­('f­low­name', inputs); 
Run a flow from a server­-side script.
sn_fd.F­lo­wAP­I.s­tar­tFl­ow(­'fl­own­ame', inputs);	
Run a flow from a server­-side script asynch­ron­ously without creating execution details
sn_fd.F­lo­wAP­I.s­tar­tFl­owQ­uic­k('­flo­wname', inputs);	
Run a subflow from a server­-side script.
sn_fd.F­lo­wAP­I.s­tar­tSu­bfl­ow(­'fl­own­ame', inputs);
Run a subflow from a server­-side script asynch­ron­ously without creating execution details
sn_fd.F­lo­wAP­I.s­tar­tSu­bfl­owQ­uic­k('­flo­wname', inputs);
Use FlowAPI methods to execute actions, flows, or subflows in server­-side scripts using either blocking or non-bl­ocking methods.
 

Comments

Can't download the file without commenting?

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Service-Now Client Side Cheats Cheat Sheet
          ServicePortal Cheat Sheet Cheat Sheet

          More Cheat Sheets by bibingokuldas

          Service-Now Client Side Cheats Cheat Sheet
          ServicePortal Cheat Sheet Cheat Sheet