Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

StandardCredentialsProvider - Scoped, Global

The StandardCredentialsProvider API provides methods to retrieve credential information.

You can use this API in scoped applications or within the global scope. In scoped scripts, use the sn_cc namespace identifier.

This API provides methods to retrieve credential information by sys_id and by specified credential attributes.

//Get a single credential

var provider = new sn_cc.StandardCredentialsProvider();
var credential = provider.getCredentialByID("f43c6d40a0a0b5700c77f9bf387afe3");
var userName = credential.getAttribute("user_name");
var password = credential.getAttribute("password");
//using getAttribute for new keys in extended tables, for example 
//cloud management credential has the "user_public_key" attribute
var userPublicKey = credential.getAttribute("user_public_key");

//Get a list of SSH credentials

var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentials(["ssh"]);
for (var i = 0; i < credentials.length; i++) {
  var credential = credentials[i];
  gs.info(credential.getAttribute("name"));
}

Parent Topic:Server API reference

StandardCredentialsProvider - StandardCredentialsProvider()

Instantiates a credentials provider object.

NameTypeDescription
None  
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID("ef43c6d40a0a0b5700c77f9bf387afe3");

StandardCredentialsProvider - getCredentials(String types, String tags)

Returns an array of all credentials that match the specified types and tags.

NameTypeDescription
tagsStringOptional. Comma-separated list of tag names. For example, "ssh, jdbc".Examples of valid calls: - `var credentials = provider.getCredentials(null, null);` - `var credentials = provider.getCredentials(["ssh"], "");` - `var credentials = provider.getCredentials(new ArrayList(), "ssh,admin");`
typesArrayOptional. Credential type names. For example, ["ssh", "windows"]Note: If types is null or empty, any match returns a credential. If types is specified, the credentials whose type matches one of the types is returned.
TypeDescription
StandardCredentialCredential record object.

This code example shows how to get the provider credentials for "ssh" credential types.

var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentials(["ssh"]);

This code example shows how to get the provider credentials for "ssh" and "windows" credential types that have tags of "admin".

var provider = new sn_cc.StandardCredentialsProvider();
ArrayList<String> types = new ArrayList<>();
types.add("ssh");
types.add("windows");
JSONArray jsonArray = provider.getCredentials(types, "admin");

StandardCredentialsProvider - getCredentialByAliasID(String sys_id)

Returns the credential record object through its credential alias (sys_alias).

This method is specifically for use with credential types. For information, see Credential aliases for Discovery.

NameTypeDescription
sys_idStringSys_id of the credential alias record in the Connection & Credential Aliases [sys_alias] table.
TypeDescription
StandardCredentialCredential record object.

The following example retrieves a credential using the alias ID and displays the user name.

var provider = new sn_cc.StandardCredentialsProvider();
var aliasCred = provider.getCredentialByAliasID("752a91887740001038e286a2681061fb");
gs.info("User name: " + aliasCred.getAttribute("user_name"));

Output for a credential record with a user name:

User name: Dara Lee

StandardCredentialsProvider - getCredentialByID(String sys_id)

Returns the credential record object identified by the specified sys_id.

NameTypeDescription
sys\_idStringSys\_id of the credential record. Table: Credentials \[discovery\_credentials\]
TypeDescription
StandardCredentialCredential record object.

The following example retrieves a credential and displays the user name.

var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID("ef43c6d40a0a0b5700c77f9bf387afe3");
gs.info("User name: " + credentials.getAttribute("user_name"));

Output for a credential record with a user name:

User name: Dara Lee

sndocs is an independent community mirror and is not affiliated with or endorsed by ServiceNow.

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are associated.

© 2026 ServiceNow, Inc. All rights reserved.

Documentation content is redistributed under the Apache License 2.0 from the ServiceNowDocs repository.