Service Portal Widget "Server Script" function($sp) or function()?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 10:09 AM
Should I be putting $sp as a function parameter or not? It seems to work either way.
(function() {
var cat_item_SYSID = $sp.getParameter('sys_id');
})();
OR
(function($sp) {
var cat_item_SYSID = $sp.getParameter('sys_id');
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 11:20 AM
You can use $sp in this way:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 11:24 AM
You do not have to include $sp as a parameter of your anonymous function on the server script. You may be confusing this with the need to inject services into your controller (client script).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 02:50 AM
You are correct. I was confusing the two. In fact, when I used
(function($sp) {
it didn't work at all. I needed to take it out for it to work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 11:36 AM
ServiceNow documentation:
The GlideSPScriptable API provides a set of methods for use in Service Portal Widgets.
You access GlideSPScriptable methods by using the global $sp object.
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GSPS-getPortalRecord