Cannot access to the $sp object through my server scrpt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2025 03:57 AM
Hi all,
I ve implemented an Assigment action by a serve side script whis is correcly executed when pushing the linked button.
I need to access my current page parameters (and properties) to elaborate server side updating.
But if I try to access the $sp object is result as null!!! Here is my server code....
Any idea please?
How do I access to my current page info?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 12:15 AM
Hi @andreadigiu,
You're almost there! Just a small correction — to access the sys_id in Service Portal Widgets, you can use the $sp API like this:
$sp.getParameter("sys_id");
Hope this helps!
If you find this helpful, please mark it as Helpful and Accept as Solution. Let me know if you need further assistance!
Thanks & Regards
Mayank
Software Engineer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 05:51 AM
Hi Maya,
The problem is not the param name that actually should be sysId (I renamed it) the problem seems to be that the script raise an error when trying to reference th $sp object which seems not to be visible in the script scope at least with that syntax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 05:55 AM
@andreadigiu Is it working now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2025 07:27 AM
hi @andreadigiu ,,
What’s happening here is pretty common: when you write a Server Script inside an Action (like the one in your screenshot), you’re running in the server-side Glide scripting context, not in the Service Portal context.
The $sp object (which comes from the Service Portal API) is only available when your script is running as part of a Widget or Scripted API within the Service Portal itself. In a Server Script behind a UI Action or Workspace Action, $sp isn’t available — that’s why it’s coming up as null.
✅ What you can do instead:
If you want to get the current record's sys_id or other parameters:
You don’t need $sp here.
Your Action already knows which record(s) it is running on, because it has the current object.
So, you can simply use
gs.addInfoMessage("XXXX>>> " + current.sys_id);
$sp is only for Service Portal Widgets.
Use current directly in your Server Script to access fields on the current record.