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

xiaix
Tera Guru

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');
})();
5 REPLIES 5

Conner M
Tera Guru

You can use $sp in this way:

data.table = $sp.getValue('table');
 
but no I don't think it matters, I have used it in the context I just gave but not as a function parameter as far as I can remember.
 
If that helps please mark it correct.

danpatino
Tera Expert

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).  

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.

Gosia Urbanska
Giga Guru

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