Anyway to use $sp.getCatalogItem method in server script

Chris Yang
Tera Sage

Hi,

 

Is there anyway to use $sp.getCatalogItem in platform server script (business rule/script include)? I could only get it working in a portal server script.

 

https://developer.servicenow.com/dev.do#!/reference/api/zurich/server/no-namespace/c_GlideSPScriptab...

3 REPLIES 3

Ct111
Giga Sage

its usage is mainly on portal side as mentioned below:

 

Ct111_0-1755492568592.png

Sample examples for reference in given in this LINK

Astik Thombare
Tera Sage

Hi @Chris Yang ,

 

The short answer is no — you cannot use $sp.getCatalogItem() in a platform server script (like a Business Rule or Script Include), because $sp is part of the Service Portal API (GlideSPScriptable). That API is only available in the Service Portal context (e.g. widget server scripts, portal processors).

 

In platform-side scripts, you don’t have $sp injected.

 

What to do instead

 

If you want the same kind of data that $sp.getCatalogItem(itemSysId) gives you, you have two main options:

 

1. Use sn_sc.CatItem Script Include

 

ServiceNow provides a backend API for catalog items:

 

var catItem = new sn_sc.CatItem(itemSysId);
var itemDetails = catItem.getItemSummary(); // returns details similar to $sp.getCatalogItem

 

Other useful methods:

 

getVariables()

 

getRequestMetadata()

 

Example:

 

var catItem = new sn_sc.CatItem('a5d12345678901234567890123456789'); // sys_id of catalog item
var summary = catItem.getItemSummary();
gs.info(JSON.stringify(summary));

 

This is the platform-safe way.

 

2. Reuse Catalog Utility APIs

If you need variable info or question sets, you can use:

 

var item = new GlideRecord('sc_cat_item');
item.get('a5d12345678901234567890123456789'); 

// to pull variables
var varSet = new GlideappVariablePoolQuestionSet();
varSet.setRequestID(-1);
varSet.setCatItem(item.sys_id);
varSet.load();

var variables = varSet.getFlatQuestions();
gs.info(variables.size());

 

Bottom line:

 

$sp.getCatalogItem() → only works in portal context.

 

Use sn_sc.CatItem or GlideappVariablePoolQuestionSet in Business Rules/Script Includes.

 

If my answer helped you, please consider marking it as Correct and giving it a 👍 Helpful — it might help other members in the community too!

 

 

Thanks,

Astik T 😊💡

kaushal_snow
Mega Sage

Hi @Chris Yang ,

 

No, you cannot use $sp.getCatalogItem directly in platform server side scripts. This method is specifically part of the Frontend ui Service Portal (GlideSPScriptable) API, and is only available within the Service Portal widget context using $sp...

 

If you need to retrieve catalog item data in platform scripts, please create a script include and put your catalog item logic into a Script Include so it can be called from various server-side.

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/