How to access credential using javascript?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-27-2018 05:55 AM
Hi, Guys. I'm new in servicenow workflow and script includes module, I'm doing an api integration wherein I would like to input the credential(api key, username, password) in javascript but I don't want my credential become viewable by other user. I saw a credential module in servicenow. Is it possible to access it in script includes(javascript)? If no, I would like to know if there's an other way to do it.
Thanks in advance!
Sev.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 11:06 PM
If it worked kindly mark the response correct and close the thread
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2018 02:06 AM
Hello, Sorry for late reply. I try your suggestion Sanjiv this is my code
var rtn = {};
try{
var r = new sn_ws.RESTMessageV2('ServiceNow Credential','get');
var response = r.execute();
rtn.requestBody = response.getBody();
gs.log(rtn.requestBody,'sevs');
}
catch(ex){
rtn.error = response.getErrorMessage();
gs.log(rtn.error,'sevs');
}
When I check the system log it appears that message "undefined" is there's any thing that i missed? I attached the set up of my created Rest Message
My assumption is since the already set the endpoint and Basic Authentication details I should not set it in my javascript. I'm I correct?
Another question is what if I want to change the endpoint in my Rest message is it acceptable if I will add this code in java script
r.setEndpoint('https://dev55879.service-now.com/api/now/table/anotherTable'); //for example
Thanks