- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 01:17 AM
I am trying to use the RESTMessageV2 when developing using the ServiceNow SDK. The project is made with TypeScript, and everything works but the sn_ws namespace.
The is the fetchWarranty function that should be used. All of the code is running when using the Background Scripts.
import { gs } from "@servicenow/glide"; /** * Fetches warranty information for a given device based on its serial number. * * This function utilizes the "Lenovo Warranty API" to retrieve the warranty details * for a specific hardware device. It constructs and executes a REST API request by * setting required headers and parameters. * * @Param {string} serialNumber - The serial number of the device for which the warranty information is to be fetched. * @returns {any} The response from the Lenovo Warranty API, or undefined if the API call fails. * * @throws Will log an error message if the REST API call fails due to exceptions. */ export const fetchWarranty = (serialNumber: string) => { try { const request = new sn_ws.RESTMessageV2( "APP_NAME.Lenovo Warranty API", "getWarranty", ); request.setRequestHeader( "ClientID", gs.getProperty("APP_NAME.client_id"), ); request.setStringParameterNoEscape("serialNumber", serialNumber); return request.execute(); } catch (ex) { const message = (ex as Error).message; gs.error("REST call failed: " + message); return; } };
I've tried importing sn_ws or RESTMessageV2 from @Servicenow/glide, but no effect.
Neither VSCode (with all relevant plugins installed) or WebStorm can autocomplete the import so it seems that it might be missing from the SDK. And as I can understand you cannot use fetch as its not allowed to use Async/Await/Promises. Is this a bug, are there any workarounds?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:09 AM
Hi there, you need to import the namespace in sys modules as they are not just exposed in global like other scripting environments in SN. Think of this more as typical module development.
import { RESTMessageV2 } from "@servicenow/glide/sn_ws"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:36 AM
Thank you BryceG.
This is exactly what I was missing. I have previously tried to import the following.
import { RESTMessageV2 } from "@servicenow/glide"
import { sn_ws } from "@servicenow/glide"
import sn_ws from "@servicenow/glide"
Is the SDK properly documented somewhere? I can only seem to find the ServiceNow SDK in the Docs. But is not really that in-depth documented.