- 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
03-02-2024 10:08 PM
@js20 that id is the sys_id of your credential record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2024 03:29 AM
i think it should be a "new" here:
var provider = new sn_cc.StandardCredentialsProvider()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 12:59 PM
Something I found when trying to get @Kieran Anson 's code to work, was that I had to add 'new' in front of 'sn_cc.StandardCredentialsProvider()', as below
var provider = new sn_cc.StandardCredentialsProvider()
var credential = provider.getCredentialByID('41cc709cdb144c101bdb5a75dc961990');
var userName = credential.getAttribute("user_name");
var password = credential.getAttribute("password");