What is spUtil #

spUtil is a really useful utility class, the problem is I can never seem
to find it when I need to look it up as it's not on
developer.servicenow.com, but is instead on
docs.servicenow.com.

So I'm making a list of their functions for my reference as it's coded
here
or
more readable
here
.

First I'll go over the documented methods, then the undocumented
methods, as there always seems to be some.

Method Documented
addErrorMessage Yes
addInfoMessage Yes
addTrivialMessage Yes
createUid No
format Yes
getAccelerator No
getHeaders No
getHost No
getPageUri No
getPreference No
getURL No
getWidgetURL No
get Yes
parseAttributes No
recordWatch Yes
refresh Yes
scrollTo No
setBreadCrumb No
setPreference No
setSearchPage No
update Yes

Documented #

addErrorMessage #

[addErrorMessage(string)] #

[record] #

.service-now.com/sp_widget_list.do?sysparm_query=id=widget-sc-cat-item

docs

// source: SC Catalog Item[widget-sc-cat-item] line 42
spUtil.addErrorMessage($scope.m.largeAttachmentMsg);

addInfoMessage #

addInfoMessage(string) #

[record] #

service-now.com/sp_widget_list.do?sysparm_query=id=widget-sc-cat-item

docs

// source: SC Catalog Item[widget-sc-cat-item] line 210
spUtil.addInfoMessage(t);//t is just a string

addTrivialMessage #

addTrivialMessage(string) #

[record] #

service-now.com/sp_widget_list.do?sysparm_query=id=widget-form

docs

// source: Form[widget-form] line 110
spUtil.addTrivialMessage(message);

format #

format(string template, object
data)
#

[record]
service-now.com/sp_widget_list.do?sysparm_query=id=widget-sc-cat-item #

docs

// source: SC Catalog Item[widget-sc-cat-item] line 198
var url = spUtil.format(
c.options.url,
{
page: page,
table: table,
sys_id: sys_id
}
);

get #

get(string
widgetid)
#

[record]
service-now.com/sp_widget_list.do?sysparm_query=id=sqanda-create-question #

docs

// source: SQANDA Create Question[sqanda-create-question] line 32
spUtil.get($scope, x).then(function(response) {
var newURL = $location.search({id: 'kb_social_qa_question', sys_id: response.data.sys_id});
spAriaFocusManager.navigateToLink(newURL.url());
});

refresh #

refresh(object
$scope)
#

docs

update #

update(object
$scope)
#

[record]
service-now.com/sp_widget_list.do?sysparm_query=sys_id=f37aa302cb70020000f8d856634c9cfc #

docs

// source: Approvals[] line 14
function get() {
spUtil.update($scope);
}

recordWatch #

recordWatch(object $scope, string table, string filter, function
callback)
#

[record]
service-now.com/sp_widget_list.do?sysparm_query=sys_id=f37aa302cb70020000f8d856634c9cfc #

docs

// source: Approvals[] line 12
spUtil.recordWatch(
$scope,
"sysapproval_approver",
"state=requested^approverIN" + $scope.data.myApprovals.toString()
);

Also, there's a number of tables that are blocked from being watched,
you can see this list in your instance by running;

gs.info(gs.getProperty("glide.record_watcher.table.blacklist"))
//this property is non-editable
  • clone_preserved_data
  • clone_token
  • digest_properties
  • instance
  • license_details
  • pa_job_logs
  • role_has_license
  • saml2_update1_properties
  • sp_log
  • sso_federation
  • sso_properties
  • sys_audit_delete
  • sys_audit_relation
  • sys_broadcast_message
  • sys_broadcast_message_m2m
  • sys_cache_flush
  • sys_cluster_message
  • sys_cluster_state
  • sys_db_cache
  • sys_dictionary_override
  • sys_email
  • sys_email_account
  • sys_email_log
  • sys_event_processor
  • sys_glide_object
  • sys_import_set
  • sys_import_set_row
  • sys_import_set_row_error
  • sys_import_set_run
  • sys_progress_worker
  • sys_progress_worker_domain
  • sys_report_summary
  • sys_report_summary_line
  • sys_rw_action
  • sys_rw_amb_action
  • sys_status
  • sys_trigger
  • sys_ui_navigator_history
  • sys_update_set
  • sys_update_set_log
  • sys_update_version
  • sys_update_xml
  • sys_upgrade_history
  • sys_upgrade_history_log
  • sys_user_preference
  • sys_user_session
  • sys_user_token
  • ua_app_metadata
  • ua_app_usage
  • usageanalytics_count
  • usageanalytics_count_cfg
  • wf_command
  • wf_context
  • wf_executing
  • wf_history
  • wf_transition_history
  • wf_workflow_execution

Undocumented #

getHeaders #

getHeaders() #

directive.spReferenceField.js#40

var headers = spUtil.getHeaders();
// returns something like so
// {
// 'Accept': 'application/json',
// 'x-portal': $rootScope.portal_id
// };

getWidgetURL #

getWidgetURL(string widgetid or string
object)
#

directive.spReferenceField.js#36

var widgetUrl = spUtil.getWidgetURL('sys_id');
// returns something like so
// '/api/now/sp/widget/sys_id';

setBreadCrumb #

setBreadCrumb(object $scope,
list)
#

[record]
service-now.com/sp_widget_list.do?sysparm_query=id=tagged-question-list

// source: Tagged Question List[] line 3
spUtil.setBreadCrumb($scope, [
{
label: c.data.community.Breadcrumb,
url: '#'
}
])

setSearchPage #

setSearchPage(searchPage) #

[record]
service-now.com/sp_widget_list.do?sysparm_query=sys_id=b8c57073cb10020000f8d856634c9cfc

// source: Search Page[] line 2
spUtil.setSearchPage($scope.data.t);//t is a string passed via url here

getURL #

getURL(type) #

[record]service-now.com/sp_widget_list.do?sysparm_query=id=widget-login

// source: Login[widget-login] line 21
var url = spUtil.getURL({sysparm_type: 'view_form.login'});
// I assume this returns a string, I'll have to check

scrollTo #

scrollTo(id,
time)
#

[record]
service-now.com/sp_widget_list.do?sysparm_query=id=widget-sc-order-guide

// source: SC Order Guide[widget-sc-order-guide] line 28
spUtil.scrollTo("#" + item.sys_id);

getAccelerator #

getAccelerator(char) #

[record]
service-now.com/sp_widget_list.do?sysparm_query=id=widget-form

// source: Form[widget-form] line 5
spUtil.getAccelerator('s');
// returns for mac '⌘ + ' + char;
// returns for otherwise 'Ctrl + ' + char;

createUid #

createUid(str) #

directive.spWidget.js#14

if (scope.widget.update) {
name += spUtil.createUid('xxxxx');
}

parseAttributes #

parseAttributes(strAttributes) #

directive.spChoiceList.js#37

function isRefQualElement(fieldName) {
var refQualElements = [];
if (field.attributes && field.attributes.indexOf('ref_qual_elements') > -1) {
var attributes = spUtil.parseAttributes(field.attributes);
refQualElements = attributes['ref_qual_elements'].split(',');
}
return field.reference_qual.indexOf(fieldName) != -1 || refQualElements.indexOf(fieldName) != -1;
}

getHost #

getHost()

setPreference #

setPreference(pref,value)

getPreference #

getPreference(pref,value)

getPageUri #

getPageUri()