How retrieve password stored as credentials into script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2025 03:56 AM
Hello Folks!
I am running into bit of a problem.
I have a script include that execute Outbound REST API call.
Trying to build this script include as safetely as possible therefore i have stored the API Key as a password in the Credentials table.
The regular glide record failed to retrieve value from that table so i found GlideCredentialUtility but i expect i am doing something wrong to get the value.
Here is my snip-set:
-------------------
sys_script_include.b04412b7475cae109371eee3716d43bc.script : Line(23) column(0)
Stack trace:
at sys_script_include.b04412b7475cae109371eee3716d43bc.script:23 (callAzureFunction)
at sys_script.81e7dee347986e109371eee3716d439d.script:5 (executeRule)
at sys_script.81e7dee347986e109371eee3716d439d.script:8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hey, have you explored the following API?
StandardCredentialsProvider - Scoped, Global
For example, in my case I needed to store an API Key in the sys_alias & api_key_credentials tables.
The way I got the API key extracted so I can use it in scripts (i.e: Triggering a REST Call with RestMessageV2) was running a code like this:
function getAPIKey(){
var credentialAliasId = "<ALIAS SYS ID>";
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByAliasID(credentialAliasId);
return credentials.getAttribute("api_key");
}
However, I noticed that, when storing the value in with a system property of type password2, the extraction is a bit faster (+-10ms).
To be honest, I have not been able to find any recommendations on where to store API Keys or Credential related information and how to use them from scripts.
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
hi ,
this throws "GlideCredentialUtility" is not defined error.
You should not query the Credentials (sys_credentials) table directly, because passwords there are encrypted.
Instead, you use the sn_auth.Credential API that ServiceNow provides.
You should not query the Credentials (sys_credentials) table directly, because passwords there are encrypted.
Instead, you use the sn_auth.Credential API that ServiceNow provides.
