- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 01:53 PM
What do I type in a business rule or scheduled job to access the credentials on the basic_auth_credentials table?
Right now, for testing purposes, I have the password and username in plain text, but of course, I would like to move that over the basic_auth_credentials table and have the script access the table to get the password and username.
I tried to look up sample code, but most of what I found on ServiceNow's doc are C#, VB, etc., and not for JavaScript. Moreover, some docs are on basic auth credentials, but it is mainly on how it works and not how to access via JavaScript from a script.
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 02:55 PM
Hi,
There is an API for this called StandardCredentialsProvider. It allows you to easily and securely get the credentials from a credentials record.
Example use (sys_id is the id of the credential record):
var provider = sn_cc.StandardCredentialsProvider()
var credential = provider.getCredentialByID('41cc709cdb144c101bdb5a75dc961990');
var userName = credential.getAttribute("user_name");
var password = credential.getAttribute("password");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 02:55 PM
Hi,
There is an API for this called StandardCredentialsProvider. It allows you to easily and securely get the credentials from a credentials record.
Example use (sys_id is the id of the credential record):
var provider = sn_cc.StandardCredentialsProvider()
var credential = provider.getCredentialByID('41cc709cdb144c101bdb5a75dc961990');
var userName = credential.getAttribute("user_name");
var password = credential.getAttribute("password");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 05:21 PM
Perfect! Just what I was looking for.
Thanks for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:56 AM
how can I get credential ID?
'41cc709cdb144c101bdb5a75dc961990'
how to set user_name and password in beginning? or is it existing credentials of some existing user?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 06:31 AM
How to you get id? its user id?