- 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-02-2025 02:45 AM
Hello @Xerrion
Actually for these cases, I would recommend - first run this in system - get the exact Python script and just convert it to "Typescript". I am not sure, But from my experience I know these languages work perfectly fine - [ServiceNow Script][cURL][Python][Ruby][JavaScript][Perl][Powershell]
It might very well be an issue because of Typescript and things are not accurately available for that yet.
I hope this answered your query.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 03:11 AM
which code is running fine in background script? share that and share screenshot of the script output
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- 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-02-2025 09:11 AM