
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2023 11:33 AM
I am attempting to populate a table in a custom application using data gathered from another tools API. The API uses GraphQL and I'm attempting to use a custom JavaScript Data Source to load the data. To do so I was trying to use the JavaScript Fetch API which to my knowledge should be included in Vanilla JavaScript, but it does not appear to be. Additionally I know my fetch request works because I am able to get the data in other JavaScript compilers.
Is there a way to make JavaScript Fetch method inside of ServiceNow? If no, is there some other way to make a GraphQL call and use the response to populate a table? Any help/thoughts would be appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2023 09:40 AM
Alright after much digging I've figured out a better method than using the JavaScript Fetch API.
It turns out that there is a way to make a GraphQl call in ServiceNow, it just takes a little workaround. I found the solution in this post but I'll also explain it here:
As noted in the post by Ihor you can make a GraphQL call using an action with a REST Step and giving it the Header "Content-Type" : "application/json". Then all you have to do is pass the body in JSON format.
Ihor did this by turning his query into a JSON format ahead of time and pasting it into the Request Body. I did it slightly differently by creating a Script step before my REST step to transform my desired request into JSON format using the JavaScript JSON.stringify() method, then passed the data pill in as the request body.
After that the GraphQL call worked as expected. Hope this helps others avoid all the headache this caused me.
 

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2023 09:40 AM
Alright after much digging I've figured out a better method than using the JavaScript Fetch API.
It turns out that there is a way to make a GraphQl call in ServiceNow, it just takes a little workaround. I found the solution in this post but I'll also explain it here:
As noted in the post by Ihor you can make a GraphQL call using an action with a REST Step and giving it the Header "Content-Type" : "application/json". Then all you have to do is pass the body in JSON format.
Ihor did this by turning his query into a JSON format ahead of time and pasting it into the Request Body. I did it slightly differently by creating a Script step before my REST step to transform my desired request into JSON format using the JavaScript JSON.stringify() method, then passed the data pill in as the request body.
After that the GraphQL call worked as expected. Hope this helps others avoid all the headache this caused me.