How to access credential using javascript?

Sev3
Tera Contributor

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.

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

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.

Sev3
Tera Contributor

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