I am working on an application in ServiceNow where I have the following UI:
I have to make a POST request when Submit is pressed. Till now I have got the following lead to make a request.
You can use the native Fetch API to make arbitrary HTTP calls, or you can use the helpers.snHttp method if you are going to be making API calls to your own ServiceNow instance
The Fetch API looks like something that I need here. When I try to run the following script, I get an error.
Script:
function sendRequest() {
var test = '';
try{ fetch('https://dummyjson.com/products/1')
.then(res => res.json())
.then(json => test = json);
}catch(e){return e;}
return test;
}
Error
TypeError: fetch is not a function
I am not finding a way to get rid of this error. I am totally new to ServiceNow scripting. Is there anything I am missing out on?