Thank you for your feedback.
Form temporarily unavailable. Please try again or contact docfeedback@servicenow.com to submit your comments.
Versions
  • London
  • Kingston
  • Jakarta
  • Istanbul
  • Helsinki
  • Geneva
  • Store
Close

Supported and unsupported client scripts

Supported and unsupported client scripts

Service Portal runs client scripts and catalog client scripts as long as the UI Type is set to Mobile or Both. Any existing client scripts set to Both, must have API calls that are supported by the mobile client scripting environment.

This section requires an advanced knowledge of client-side scripting and Service Portal APIs.

Unsupported client scripting globals

The following globals and APIs are unavailable in Service Portal client script:

  • window
  • document
  • $
  • jQuery
  • $$
  • $j
  • angular

Client scripting in widgets

Widget client controllers are full angular controllers and are not subject to the restrictions listed above. Use jQuery and Angular as needed.

Embedded widgets & g_form

When using the Service Catalog variable type Macro and Macro with Label you can pick a widget to embed in a catalog item form. Within that embedded widget's client controller you can access the field object and catalog item g_form instance using:

  • $scope.page.field
  • $scope.page.g_form()

Checking desktop vs mobile runtime

You might want to mark a client script compatible with both desktop and mobile but still do something different depending on the runtime use this:
  if (window === null)
    // Write your mobile compatible code here
  else
    // Write your desktop compatible code here

Supported client scripting APIs

These are the supported client scripting APIs you can use in onLoad, onChange, and onSubmit client scripts.

g_form

  • addDecoration(fieldName, icon, title)
  • addErrorMessage(message)
  • addInfoMessage(message)
  • addOption(fieldName, value, label, index)
  • clearMessages()
  • clearOptions(fieldName)
  • clearValue(fieldName)
  • getActionName()
  • getBooleanValue(fieldName)
  • getDecimalValue(fieldName)
  • getEncodedRecord()
  • getFieldNames()
  • getIntValue(fieldName)
  • getLabel(fieldName)
  • getReference(fieldName, callback)
  • getRelatedListNames()
  • getSectionNames()
  • getSysId()
  • getTableName()
  • getValue(fieldName)
  • hasField(fieldName)
  • hideAllFieldMsgs(type: "info | error")
  • hideErrorBox(fieldName)
  • hideFieldMsg(fieldName, clearAll)
  • hideRelatedList(listTableName)
  • hideRelatedLists()
  • isMandatory(fieldName)
  • isNewRecord()
  • isReadOnly(fieldName)
  • isVisible(fieldName)
  • removeDecoration(fieldName, icon, title)
  • removeOption(fieldName, value)
  • save()
  • serialize(onlyDirtyFields)
  • setFieldPlaceholder(fieldName, placeholder)
  • setLabel(fieldName, label)
  • setMandatory(fieldName, isMandatory)
  • setReadOnly(fieldName, isReadOnly)
  • setSectionDisplay(sectionName, isVisible)
  • setValue(fieldName, value, displayValue)
  • setVisible(fieldName, isVisible)
  • showErrorBox(fieldName, message, scrollForm)
  • showFieldMsg(fieldName, message, type: "info | error", scrollForm)
  • showRelatedList(relatedTableName)
  • showRelatedLists()
  • submit(submitActionName)
Note: Using the variables.var_name notation with the g_form API is not supported in Service Portal.

g_list

  • get(fieldName)
    • addItem(value, displayValue)
    • removeItem(value)
    • reset()
    • setQuery(queryString)
    • setDefaultOperator(operator)
    • getDefaultOperator()

g_service_catalog

isOrderGuide()

GlideAjax

new GlideAjax(scriptIncludeName)
  • addParam (name, value)
  • getParam (name)
  • getXML(callback)
  • getXMLAnswer(callback)
  • getJSON(callback)
  • getXMLAnswer()
  • setErrorCallback(errorCallback)
  • getURL()
  • getParams()
  • execute()
  • successCalback(data, status, xhr)
  • errorCallback(xhr)
  • setScope(scope)

GlideRecord

new GlideRecord(tableName)
  • addQuery(encodedQuery)
  • addQuery(fieldName, operator, value)
  • getEncodedQuery()
  • get(id)
  • getTableName()
  • hasNext()
  • insert(callback)
  • gotoTop()
  • next()
  • loadRow(rowObj)
  • getValue(fieldName)
  • setValue(fieldName, value)
  • isDotWalkField(fieldName)
  • orderByDesc(fieldName)
  • setDisplayFields(fieldNames)
  • query(callback)
  • setRows(rowsArray)
  • setTableName(tableName)
  • setLimit(maxInt)
  • getLimit()

getMessage(messageKey, callback)