Cannot access to the $sp object through my server scrpt

andreadigiu
Tera Contributor

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

andreadigiu_0-1751626604492.png

 

Any idea please?

How do I access to my current page info?

Thanks

6 REPLIES 6

mayankkumar
Tera Sage

 

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

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

@andreadigiu Is it working now?

Community Alums
Not applicable

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.