What is gs

gs is very heavily used in Servicenow, and as such, knowing what it can, and cannot do is crucial. Below I go over the functions I’m aware of and what they do. Below these things refer to the availability based on weather you are in global scope or in your own scope.

Property / Method Documented Description
addErrorMessage Global/Scoped Adds an error message for the current session.
addInfoMessage Global/Scoped Adds an info message for the current session.
addMessage Global Adds a message for the current session. Can be called using getMessages(String).
base64Decode Scoped
base64Encode Scoped
cacheFlush
clearMessages
debug Scoped
disableSessionScopeDebug
dropColumnQuick
dropTable
enableDomain
error Scoped
eventQueueScheduled Global/Scoped Queues an event for the event manager at a specific date/time.
eventQueue Global/Scoped Queues an event for the event manager.
executeNow Scoped
fieldExists
flushAccessMessages
flushMessages Global Clears session messages saved using addErrorMessage(Object) or addInfoMessage(Object).
flushWorkflow
generateGUID Scoped
getAccessMessages
getCallerScopeName Scoped
getCssCacheVersionString Scoped
getCurrentApplicationId Scoped
getCurrentApplicationScope
getCurrentScopeName Global/Scoped [gets the name of the current scope.
getDisplayColumn Global Gets the display column for the table.
getDisplayValueFor Global Gets the display value for a given field.
getErrorMessages Global/Scoped Gets the list of error messages for the session that were added by addErrorMessage(Object).
getEscapedMessage Scoped
getEscapedProperty Global Gets the property and escapes it for XML parsing.
getImpersonatingUserDisplayName Global Returns the display name of the impersonating user.
getImpersonatingUserName Global Returns the name of the impersonating user or null if not impersonating.
getInfoMessages Global Gets the list of info messages for the session that were added via addInfoMessage(Object.
getMessages Global Gets the list of messages of the specified type for the session that were added via addMessage().
getMessageS Global Retrieves translated messages to display in the UI and escapes all ticks (’).
getMessage Global/Scoped Retrieves translated messages to display in the UI.
getNodeName Global Returns the node name for specified index.
getNodeValue Global Gets the node value for specified index.
getPreference Global Gets a user preference.
getProperty Global/Scoped Gets the value of a Glide property.
getScriptError Global Returns the script error found in the specified script, if there is one.
getSessionID Global/Scoped Accesses the GlideSession Session ID.
getSessionToken Scoped
getSession Global/Scoped Returns a GlideSession object.
getStyle Global Returns the style defined for the table, field and value.
getTimeZoneName Scoped
getTrivialMessages Global Gets the list of error messages for the session that were added with the trivial flag.
getUrlOnStack Scoped
getUserDisplayName Global/Scoped Returns the name field of the current user (e.g. John Smith, as opposed to smith).
getUserID Global/Scoped Returns the sys_id of the current user.
getUserNameByUserID Global Gets the username based on a user ID.
getUserName Global/Scoped Returns the username of the current user (for example, jsmith).
getUser Global/Scoped Returns a reference to the User object for the current user. More information is available here.
getXMLNodeList Global Constructs an Array of all the nodes and values in an XML document.
getXMLText Global Gets the xml text for the first node in the xml string that matches the path query.
hasRoleInGroup Global Determines if the current user has the specified role within a specified group.
hasRole Global/Scoped Determines if the current user has the specified role.
include Scoped
info Scoped
isCurrentApplicationCustom
isCurrentApplicationInGlobalScope
isDatabaseView
isDebugging Scoped
isInteractive Global/Scoped Checks if the current session is interactive.
isLoggedIn Global/Scoped Determines if the current user is currently logged in.
isMobile Scoped
isPaused
isTableInScope
isValidScript
loadGlobalScripts
logError Global Logs an error to the system log and saves it to the syslog table.
logWarning Global Logs a warning to the system log and saves it to the syslog table.
log Global Logs a message to the system log and saves it to the syslog table.
nil Global/Scoped Queries an object and returns true if the object is null or contains an empty string.
print Global Writes a message to the system log.
sendRedirect
setCurrentApplicationId
setProperty Global/Scoped Sets the specified key to the specified value.
setRedirect Global/Scoped Sets the redirect URI for this transaction. This determines the next page the user will see.
setReturn Global Sets the return URI for this transaction.
sleep
suppressTextIndex
suppressUpdateSynch
tableExists Global/Scoped Determines if a database table exists.
templateOrMacroExists
unloadChoices
unWrap
updateSave
urlDecode Scoped
urlEncode Scoped
userID Global Returns the sys_id of the user associated with this session.
user_id
warn Scoped
workflowFlush Global Deletes all existing workflow operations for the specified GlideRecord.
xmlToJSON Scoped Converts an xml string to json object.
beginningOfLastMonth Global/Scoped Gets the date and time for the beginning of last month in GMT.
beginningOfLastWeek Global/Scoped Gets the date and time for the beginning of last week in GMT.
beginningOfNextMonth Global/Scoped Gets the date and time for the beginning of next month in GMT.
beginningOfNextWeek Global/Scoped Gets the date and time for the beginning of next week in GMT.
beginningOfNextYear Global/Scoped Gets the date and time for the beginning of next year in GMT.
beginningOfThisMonth Global/Scoped Gets the date and time for the beginning of this month in GMT.
beginningOfThisQuarter Global/Scoped Gets the date and time for the beginning of this quarter in GMT.
beginningOfThisWeek Global/Scoped Gets the date and time for the beginning of this week in GMT.
beginningOfThisYear Global/Scoped Gets the date and time for the beginning of this week in GMT.
beginningOfToday Global Gets the date and time for the beginning of today in GMT.
beginningOfYesterday Global Gets the date and time for the beginning of yesterday in GMT.
calDateDiff Global Calculate the difference between two dates using the default calendar.
dateDiff Global Calculates the difference between two dates.
dateGenerate Global/Scoped Generates a date and time for the specified date in GMT.
daysAgoEnd Global/Scoped Gets a date and time for end of the day a certain number of days ago.
daysAgoStart Global/Scoped Gets a date and time for beginning of the day a certain number of days ago.
daysAgo Global/Scoped Gets a date and time for a certain number of days ago.
endOfLastMonth Global/Scoped Gets the date and time for the end of last month in GMT.
endOfLastWeek Global/Scoped Gets the date and time for the end of last week in GMT, in the format yyyy-mm-dd hh:mm:ss.
endOfLastYear Global/Scoped Gets the date and time for the end of last year in GMT.
endOfNextMonth Global/Scoped Gets the date and time for the end of next month in GMT.
endOfNextWeek Global/Scoped Gets the date and time for the end of next week in GMT.
endOfNextYear Global/Scoped Gets the date and time for the end of next year in GMT.
endOfThisMonth Global/Scoped Gets the date and time for the end of this month in GMT.
endOfThisQuarter Global/Scoped Gets the date and time for the end of this quarter in GMT.
endOfThisWeek Global/Scoped Gets the date and time for the beginning of this week in GMT.
endOfThisYear Global/Scoped Gets the date and time for the end of this year in GMT.
endOfToday Global Gets the date and time for the end of today in GMT.
endOfYesterday Global Gets the date and time for the end of yesterday in GMT.
hoursAgoEnd Global/Scoped Gets a date and time for the end of the hour a certain number of hours ago.
hoursAgoStart Global/Scoped Gets a date and time for the start of the hour a certain number of hours ago.
hoursAgo Global/Scoped Gets a date and time for a certain number of hours ago.
isFirstDayOfMonth Global Checks whether the date is the first day of the month.
isFirstDayOfWeek Global Checks whether the date is the first day of the week(Monday).
isFirstDayOfYear Global Checks whether the date is the first day of the year
isLastDayOfMonth Global Checks whether the date is the last day of the month.
isLastDayOfWeek Global Checks whether the date is the last day of the week.
isLastDayOfYear Global Checks whether the date is the last day of the year.
lastWeek Global Date and time one week ago in GMT.
minutesAgoEnd Global Gets a date and time for the end of the minute a certain number of minutes ago.
minutesAgoStart Global Gets a date and time for a certain number of minutes ago.
minutesAgo Global Gets a date and time for a certain number of minutes ago.
monthsAgoEnd Global/Scoped Gets a date and time for the last day of the month a certain number of months ago.
monthsAgoStart Global/Scoped Gets a date and time for the first day of the month a certain number of months ago.
monthsAgo Global/Scoped Gets a date and time for a certain number of months ago.
nowDateTime Global Gets the current date and time.
nowGlideDateTime Global Returns a GlideDateTime object with the current date and time.
nowNoTZ Global Gets the current GMT date time.
now Global Gets the current date.
quartersAgoEnd Global/Scoped Gets a date and time for the last day of the quarter a certain number of quarters ago.
quartersAgoStart Global/Scoped Gets a date and time for the first day of the quarter a certain number of quarters ago.
quartersAgo Global Gets a date and time for a certain number of quarters ago.
yearsAgo Global/Scoped Gets a date and time for a certain number of years ago.
yesterday Global/Scoped Gets yesterday’s time.

addErrorMessage

This is a way to display an error message to a user.

gs.addErrorMessage(gs.getMessage("To make a survey public, you need remove the signature"));

GS Add Error Message

addInfoMessage

This is a way to display an infomational message to a user.

gs.addInfoMessage(gs.getMessage("{0}.  Hello!", 'I am no 1'));

GS Add Info Message

addMessage

This is a older method to add a message. I’d highly suggest not using this, however you can and if you want to see the result you can do so with the Xplore application.

//I don't suggest using this...
gs.addMessage('test','again');
gs.addMessage('test','again2');
var messages = gs.getMessages('test').toString();
gs.print(messages);//seems to work in Xplore but doesnt echo the contents in background scripts

base64Decode

There is a post on John Anderson’s site about base64 encoding and decoding.

Here’s the bit;

Base 64 encoding is a method used to convert binary data into ASCII strings. This is especially helpful if you want to convert a file, picture, or other object into a string in order to distribute it through mechanisms such as web services or database storage.

This type of encoding will convert any sort of data into a string of case-sensitive letters and numbers. While the result will generally be a longer string of text than its original counterpart, it offers benefits such as taking a variety of types of data and converting it to something that can be passed over a URL, or stored in a text field.

While there is little documentation on converting data to base 64 format in ServiceNow, it can actually be done with a single line of code. The following code snippet will take a string and convert it to its base 64 equivalent and printed to the log. It will then take that new base64 string and decode back it its original format and write it to the system log.

gs.base64Encode("My String");
gs.base64Decode("ENCODEDSTRINGGOESHERE");

base64Encode

There is a post on John Anderson’s site about base64 encoding and decoding.

Here’s the bit;

Base 64 encoding is a method used to convert binary data into ASCII strings. This is especially helpful if you want to convert a file, picture, or other object into a string in order to distribute it through mechanisms such as web services or database storage.

This type of encoding will convert any sort of data into a string of case-sensitive letters and numbers. While the result will generally be a longer string of text than its original counterpart, it offers benefits such as taking a variety of types of data and converting it to something that can be passed over a URL, or stored in a text field.

While there is little documentation on converting data to base 64 format in ServiceNow, it can actually be done with a single line of code. The following code snippet will take a string and convert it to its base 64 equivalent and printed to the log. It will then take that new base64 string and decode back it its original format and write it to the system log.

gs.base64Encode("My String");
gs.base64Decode("ENCODEDSTRINGGOESHERE");

cacheFlush

gs.cacheFlush();
/* Output
Starting cache flush
Flushing cache
Loading properties from DB
Cache flush complete
*/

clearMessages

This is related the addMessage method above. Like that one, I don’t see any reason to use this.

gs.clearMessages()

debug

This method was added around the time scoped apps were added as gs.print was made unavailable. In anycase, this is just a level of logging.

gs.debug('This is a message with {0}, {1}, {2}, {3}, {4} parameters','one','two','three','four','five');
//*** Script: [DEBUG] This is a message with one, two, three, four, five parameters

disableSessionScopeDebug

dropColumnQuick

//this seems to be used by a business rule when a sys_dictionary element is deleted.
if(GlideTableDescriptor.fieldExists(current.name.toString(), current.element.toString())) {
  var duplicates = new GlideRecord('sys_dictionary');
  duplicates.addQuery('name',current.name);
  duplicates.addQuery('element',current.element);
  duplicates.query();
  if (!duplicates.next()) {
    gs.dropColumnQuick(current.name, current.element);
  }
}

dropTable

gs.dropTable(this.tableName);

enableDomain

error

This method was added around the time scoped apps were added as gs.print was made unavailable. In anycase, this is just a level of logging.

gs.error('This is a message with {0}, {1}, {2}, {3}, {4} parameters','one','two','three','four', 'five');
//*** Script: This is a message with one, two, three, four, five parameters: no thrown error

eventQueueScheduled

This creates a sysevent record with a process_on to be set to the specified date and time.

This takes six properties, with the last being optional.

Parameter Description
Parameter 1 Event name, should be registered
Parameter 2 GlideRecord object the event gets access to
Parameter 3 A string the event has access to via parm1
Parameter 4 A string the event has access to via parm2
Parameter 5 A GlideDateTime to set the process_on on the event
var gdt = new GlideDateTime();
gdt.addSeconds(100);
var inc = new GlideRecord('incident');
inc.setLimit(1);
inc.query();
if(inc.next()){
  gs.print('...');
  gs.eventQueueScheduled('user.view', inc, 'Parm1', 'Parm2', gdt);
}

eventQueue

This takes five properties, with the last being optional.

Parameter Description
Parameter 1 Event name, should be registered
Parameter 2 GlideRecord object the event gets access to
Parameter 3 A string the event has access to via parm1
Parameter 4 A string the event has access to via parm2
Parameter 5 Optional. Event Queue to run this on
gs.eventQueue('cost_center.affected', current, itemSysID, itemName);

executeNow

//gs.executeNow();

fieldExists

gs.fieldExists('incident', 'rfc')

flushAccessMessages

flushMessages

flushWorkflow

generateGUID

gs.generateGUID();

getAccessMessages

getCallerScopeName

getCssCacheVersionString

gs.getCssCacheVersionString();

getCurrentApplicationId

getCurrentApplicationScope

getCurrentScopeName

gs.getCurrentScopeName();

getDisplayColumn

getDisplayValueFor

getErrorMessages

Returns the list of error messages for the session that were added by addInfoMessage().

gs.addErrorMessage('one');
gs.addErrorMessage('two');
gs.addErrorMessage('three');
gs.addErrorMessage('four');
gs.print(gs.getErrorMessages()); // returns [one, two, three, four];

getEscapedMessage

getEscapedProperty

getImpersonatingUserDisplayName

//returns null if not impersonating
//otherwise retruns string
gs.getImpersonatingUserDisplayName();

getImpersonatingUserName

//returns null if not impersonating
//otherwise retruns string
gs.getImpersonatingUserName();

getInfoMessages

Returns the list of info messages for the session that were added by addInfoMessage().

gs.addInfoMessage('one');
gs.addInfoMessage('two');
gs.addInfoMessage('three');
gs.addInfoMessage('four');
gs.print(gs.getInfoMessages()); // returns [one, two, three, four];
gs.addInfoMessage('five');

getMessages

This is related the addMessage method above. Like that one, I don’t see any reason to use this.

//I don't suggest using this...
gs.addMessage('test','again');
gs.addMessage('test','again2');
var messages = gs.getMessages('test').toString();
gs.print(messages);//seems to work in Xplore but doesnt echo the contents in background scripts

getMessageS translated

getMessage

This is related the addMessage method above. Like that one, I don’t see any reason to use this.

getNodeID

This is undocumented. This seems to return the sys_id of the sys_cluster_state the current script is running on. It can be found in the Scripted Web Service InstanceInfo.

// resp.result.node_id = ensure(gs.getNodeID());
gs.print(gs.getNodeID());
// 98a4fd3f0ede2c576c28d9b0a3a6073b

getSystemID

This is undocumented. This seems to return the system_id of the sys_cluster_state the current script is running on. It can be found in the Scripted Web Service InstanceInfo.

// resp.result.system_id = ensure(gs.getSystemID());
gs.print(gs.getSystemID());
// app128069.sin1.service-now.com:dev32369555

getInstanceIP

This is undocumented. This seems to return a IP address. It can be found in the Scripted Web Service InstanceInfo.

// resp.result.instance_ip = ensure(gs.getInstanceIP());
gs.print(gs.getInstanceIP());
// 10.132.128.69

getNodeValue

getPreference

gs.getPreference('table.compact');

getProperty

This returns the value of a property, or if the property doesn’t exist, the second parameter.

//returns property or parm2
gs.getProperty("glide.sc.checkout.twostep", "false");

getScriptError

This is undocumented. This however doesn’t seem to actually return anything.

//var error = gs.getScriptError(current.script);
var errorScript = 'var a = 1;var b = 0;console.log(a/b);';
var error = gs.getScriptError(errorScript);
gs.print(error);//retuns null

getSessionID

Returns the GlideSession Session ID.

gs.getSessionID();
// FE2A72810F321300FC69CDBCE1050EBA

getSessionToken

This defines the g_ck defined in most places.

gs.getSessionToken();

getSession

Gets a session object as documented here.

gs.getSession();

getStyle

getTimeZoneName

I think this is part of GlideSession

getTrivialMessages

getUrlOnStack

gs.getUrlOnStack();

getUserDisplayName

gs.getUserDisplayName();

getUserID

var userID = gs.getUserID();
gs.print(userID);
// *** Script: d7004dd20f021300fc69cdbce1050eff

getUserNameByUserID

getUserName

gs.getUserName();

getUser

Gets a user obj.

gs.getUser();

getXMLNodeList

getXMLText

Gets the text of a xml node.

var symbol = gs.getXMLText(current.payload, "//StockQuotes/Stock/Symbol");

hasRoleInGroup

hasRole

gs.hasRole("mid_server");//returns true/false

include

info

This method was added around the time scoped apps were added as gs.print was made unavailable. In anycase, this is just a level of logging.

gs.info('This is a message with {0}, {1}, {2}, {3}, {4} parameters','one','two','three','four','five');
//*** Script: This is a message with one, two, three, four, five parameters

isCurrentApplicationCustom

gs.isCurrentApplicationCustom();//returns true/false

isCurrentApplicationInGlobalScope

gs.isCurrentApplicationInGlobalScope();//returns true/false

isDatabaseView

gs.isDatabaseView(ListProperties.getTable();//returns true/false

isDebugging

isInteractive

gs.isInteractive();//returns true/false

isLoggedIn

If you’re logged in returns true, else, false.

gs.isLoggedIn();//returns true/false

isMobile

According to this page you should use gs.isMobile() to determine whether or not an action was taken through a mobile UI.

Additionally, you can use this to prevent a UI action from appearing in the mobile interface.

gs.isMobile();//returns true/false

isPaused

// if we're paused, then upgrade is running...
if (gs.isPaused()) {}

isTableInScope

gs.isTableInScope();//returns true/false

isValidScript

gs.isValidScript(current.script);

loadGlobalScripts

gs.loadGlobalScripts();

logError

This method is not available to scoped applications, so I’d suggest using gs.info() instead.

This creates a record on the syslog table with a level of 2.

gs.logError('message','source');

logWarning

This method is not available to scoped applications, so I’d suggest using gs.info() instead.

This creates a record on the syslog table with a level of 1.

gs.logWarning('message','source');

log

This method is not available to scoped applications, so I’d suggest using gs.info() instead.

This creates a record on the syslog table with a level of 0.

gs.log('message','source');

nil

This is undocumented. It’s used all over though. Below is a ACL script on kb_social_qa_subscribe.

if(gs.nil(current.question) || current.operation() == 'insert')
  answer = true;
else
  answer = new SocialQACommon().canRead(current.question.kb_knowledge_base);

print

This method is not available to scoped applications, so I’d suggest using gs.info() instead.

gs.print('hello world');

sendRedirect

This is undocumented. It appears to always be used when wanting to redirect the user. I’m not sure how its differetn then setRedirect. You can see this in use on the UI Page assessment_take2.

// ...
function saveAssessment() {
  if (!instance_sysID) {
    gs.log('Error in submitting assessment instance');
    gs.sendRedirect('home.do');
  }
// ...

setCurrentApplicationId

This is undocumented. It can be found a few places. The business rule “Set Current Application” seems self explantory;

gs.setCurrentApplicationId(current.sys_id);
//...

setProperty

Sets the specified key to the specified value if the property is within the script’s scope.

gs.setProperty("glide.foo","bar","foo");
gs.info(gs.getProperty("glide.foo"));

setRedirect

Sets the redirect URI for this transaction, which then determines the next page the user will see.

var path = "com.glideapp.servicecatalog_cat_item_view.do?";
path += "sysparm_id=d41ce5bac611227a0167f4bf8109bf70&";
path += "sysparm_user=" + current.sys_id;
path += "&sysparm_email=" + current.email;
gs.setRedirect(path);

setReturn

This is only available in global.

Sets the return URI for this transaction. This determines what page the user will be directed to when they return from the next form.

gs.setReturn (current.getLink(true));

sleep

I am really suprised this is undocumented, but it is. It’s used out of box a few places. This expects a number for the quantity of milleseconds to delay the server processing.

var timeInMS = 1000;//1 second in milleseconds
gs.sleep(timeInMs);

suppressTextIndex

This is undocumented and found a few places, one of which is the UI Page service_preview_generator.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
   <g:evaluate var="jvar_new_staged_id" jelly="true">
      var oldStagedGR = new GlideRecord("sc_ic_item_staging");
      var newStagedID = "";
      if (oldStagedGR.get(jelly.sysparm_staged_item)) {
         var updateSynchWasSuppressed = gs.suppressUpdateSynch(true);
         var textIndexWasSuppressed = gs.suppressTextIndex(true);
         try {
            newStagedID = copyDraftService(jelly.sysparm_staged_item, oldStagedGR.name);
            var newStagedGR = new GlideRecord("sc_ic_item_staging");
            newStagedGR.get(newStagedID);
            sc_ic_Factory.wrap(newStagedGR).publish();
         } catch(e) {
         } finally {
            gs.suppressUpdateSynch(updateSynchWasSuppressed);
            gs.suppressTextIndex(textIndexWasSuppressed);
         }
      }
      newStagedID;
   </g:evaluate>

   <j:if test="${newStagedID != ''}">
      <script>
         document.location.href = "service_preview.do?sysparm_id=${jvar_new_staged_id}${AMP}sysparm_preview=true";
      </script>
   </j:if>
</j:jelly>

suppressUpdateSynch

This is undocumented and found a few places, one of which is the UI Action called, “Preview Service”.

var newServiceID = '';
var wasSuppressed = gs.suppressUpdateSynch(true);
try {
   var newServiceID = copyDraftService(current.getUniqueValue(), current.name);
   var newServiceGR = new GlideRecord("sc_ic_item_staging");
   newServiceGR.get(newServiceID);
   sc_ic_Factory.wrap(newServiceGR).publish();
} catch(e) {
} finally {
   gs.suppressUpdateSynch(wasSuppressed);
}
if (newServiceID != '')
   action.setRedirectURL("service_preview.do?sysparm_id=" + newServiceID + "&sysparm_preview=true&sysparm_staged_image_id=" + current.getUniqueValue());

tableExists

Determines if a database table exists.

gs.tableExists('live_group_profile');
// true if table exists, otherwise false.

templateOrMacroExists

This is undocumented and found on the catalog_item UI Macro;

<g2:evaluate var="jvar_exists">
    var templateName ='com.glideapp.servicecatalog_' +
    sc_cat_item.sys_class_name + '.xml';
    gs.templateOrMacroExists(templateName);
</g2:evaluate>

unloadChoices

This is not documented and found on the Choices unload business rule for Table [sys_choice]. I believe this is what adds all choices to an update set when the sys_choice gets modified. It’s just a guess.

gs.unloadChoices(current.name, current.element, 'true');

unWrap

This is not documented and found on the assesment_redirect UI Page. Below I’ve listed the HTML and client script.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
  <g2:evaluate var="jvar_unwrapped_url" jelly="true">
    var url = jelly.sysparm_survey_url;
    url = gs.unWrap(url);
    url;
  </g2:evaluate>
  ${gs.getMessage("Redirecting to your survey")}...
</j:jelly>
document.location.href = "$[JS:jvar_unwrapped_url]";

updateSave

gs.updateSave(current);

urlDecode

This doesn’t seem to work. I tried the following script and it just sets the variable to undefined. Below is what the docs say about this;

Replaces UTF-8 encoded characters with ASCII characters.

var decoded = gs.urlDecode('https://dev32369.service-now.com/nav_to.do?uri=%2Fsys.scripts.do');
gs.print(decoded);
// *** Script: undefined

urlEncode

This doesn’t seem to work. I tried the following script and it just sets the variable to undefined. Below is what the docs say about this;

Encodes non-ASCII characters, unsafe ASCII characters, and spaces so the returned string can be used on the Internet. Uses UTF-8 encoding. Uses percent (%) encoding.

var encoded = gs.urlEncode('https://dev32369.service-now.com/nav_to.do?uri=%2Fsys.scripts.do');
gs.print(encoded);
// *** Script: undefined

userID

This returns the logged in user’s sys_id.

var userID = gs.userID();
gs.print(userID);
// *** Script: d7004dd20f021300fc69cdbce1050eff

user_id

var userID = gs.user_id();
gs.print(userID);
// *** Script: d7004dd20f021300fc69cdbce1050eff

warn

This method was added around the time scoped apps were added as gs.print was made unavailable. In anycase, this is just a level of logging.

gs.warn('This is a message with {0}, {1}, {2}, {3}, {4} parameters','one','two','three','four', 'five');
//*** Script: This is a message with one, two, three, four, five parameters

workflowFlush

xmlToJSON

Takes an XML string and returns a JSON object. This seems to be similar to the XMLHelper script include function, toObject.

var xmlStr = "";
xmlStr += "<Names>";
xmlStr += "  <Name>";
xmlStr += "    <FirstName>John</FirstName>";
xmlStr += "    <LastName>Smith</LastName>";
xmlStr += "  </Name>";
xmlStr += "  <Name>";
xmlStr += "    <FirstName>James</FirstName>";
xmlStr += "    <LastName>White</LastName>";
xmlStr += "  </Name>";
xmlStr += "</Names>";

var xmlObj = gs.xmlToJSON(xmlStr);
gs.info(JSON.stringify(xmlObj,'','  '));
/*** Script: {
  "Names": {
    "Name": [
      {
        "FirstName": "John",
        "LastName": "Smith"
      },
      {
        "FirstName": "James",
        "LastName": "White"
      }
    ]
  }
}*/