- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:58 AM
Hello,
I saw that I could retreive an RITM informations using the REST API, and I have no problem retreiving them using the link in my browser:
(mySNow.com/api/now/table/sc_req_item?sysparm_query=number%RITMXXXX&sysparm_fields=priority)
but I am unable to get the same Json data when I'm inside a Script Include.
I think it's possible but I guess I'm not doing it in the proper way.
I already tried the js "fetch()" with the rights header but didn't work.
If you ever had the case, let me know how did you do !
Thanks,
Regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 05:42 AM
Hi @Julien GOUPIL ,
Hope you are doing well.
I tried the below code in background script and seems to be working. You can adjust this code to use in script include.
var sm = new sn_ws.RESTMessageV2();
sm.setEndpoint("your rest end point URL");
sm.setHttpMethod('GET');
var user = 'xxxx'; // The user ID should have access to the ritm table
var password = 'xxxx';
sm.setBasicAuth(user,password);
sm.setRequestHeader("Accept","application/json");
var response = sm.execute();
gs.log(response.getBody()); // Will get you JSON data
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 05:42 AM
Hi @Julien GOUPIL ,
Hope you are doing well.
I tried the below code in background script and seems to be working. You can adjust this code to use in script include.
var sm = new sn_ws.RESTMessageV2();
sm.setEndpoint("your rest end point URL");
sm.setHttpMethod('GET');
var user = 'xxxx'; // The user ID should have access to the ritm table
var password = 'xxxx';
sm.setBasicAuth(user,password);
sm.setRequestHeader("Accept","application/json");
var response = sm.execute();
gs.log(response.getBody()); // Will get you JSON data
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Harshal