Service Portal Error: Server Javascript error "\$sp" is not defined

reginabautista
Kilo Sage

Hi guys I am encountering   the below error when creating a new record.

find_real_file.png

The code below would update the Number of Requests on the Header Menu whenever a record is saved (current user):

find_real_file.png

The code is located in Service Portal Menu header-> Menu Items. Type   = Scripted List.

var st = new GlideRecord('myTable');

if (st.isValid()) {

  st.addActiveQuery();

  st.addQuery('opened_by', gs.getUserID());

  st.orderByDesc('sys_updated_on');

  st.setLimit(max);

  st.query();

  while (st.next()) {

      var a = {};

      $sp.getRecordValues(a, st, 'request_description,sys_id,number,sys_updated_on'); This is where the error is occuring

      if (st.request_description.nil())

      //   a.short_description = st.request_description;

      a.__table = st.getTableName();

      a.type = 'record';

  //   a.sortOrder = st.sys_updated_on.getGlideObject().getNumericValue();

      t.items.push(a);

  }

}

This code works perfectly for the Incident table. But for some reason is not working in my custom table. Any idea why?

1 ACCEPTED SOLUTION

No fix. An evangelist told me to open a HI ticket with ServiceNow.



I know this doesn't solve your problem, but it's a start.


View solution in original post

10 REPLIES 10

No problem. Please mark this as answered.


Nia McCash
Mega Sage
Mega Sage

reginabautista cmcclendon - Did either of you get an answer for this from HI?   I am running into this issue as well in Kingston patch 1 in a scoped app.


No answer. I have seen a few workarounds attempted, but this must be low on the totem pole.


Daniel Pettet
ServiceNow Employee
ServiceNow Employee

You should note that the $sp scoped version is called "GlideSPScriptable".

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideSPScriptableScoped/concept/c_GlideSPScriptableScopedAPI.html

 

I however had an issue with "Scripted List" menu items that made $sp calls. Even replacing "$sp" with "GlideSPScriptable" didn't fix the issue (Kingston.p2) due to some kind of internal script sourcing issue (according to Hi support).

The recommendation for now is to only work on those problematic menu items in the global scope. 

Joost3
Mega Contributor

I've been working around this issue by replacing:

$sp.getRecordValues(a, st, 'request_description,sys_id,number,sys_updated_on');

with:

a.request_description = st.request_description.getDisplayValue();
a.sys_id = st.sys_id.getDisplayValue();
a.number = st.number.getDisplayValue();
a.sys_updated_on = st.sys_updated_on.getDisplayValue();