The CreatorCon Call for Content is officially open! Get started here.

Location to store credentials for later use in scripts

Andrei Radules1
Giga Contributor

Hello,

I am using a set of credentials in one of my script so that I can retreive some data.

Is there any place in ServiceNow where I can store these credentials so I can just call them in scripts ?

Best would be if they were a Password 2 field type so I can decrypt them in the script only or a password that I can encode.

I am interested if there is any standard place for storing this sort of intro, I would like to not add any fields or make modifications to other tables.

Any ideas ?

Thank you !

1 ACCEPTED SOLUTION

SatheeshKumar
Kilo Sage

Use system properties to store the password.

 

You can create a system property record of type password/password2.

 

for more details check the below link:

https://docs.servicenow.com/bundle/london-platform-administration/page/administer/reference-pages/task/t_AddAPropertyUsingSysPropsList.html 

 

-satheesh

 

View solution in original post

5 REPLIES 5

Chris Nack
Tera Expert

See the Credentials module under Connections and Credentials. You could store your credentials as a Basic Auth type of credential for example if none of the other credential types is an exact match. The password is stored securely in a password2 type field. Then you can use a regular query on the [discovery_credentials] table, searching for your credentials by the name you stored them under to get the sysid of the credential record. Then use the following code to get the userid and password. For example, I created a set of credentials with the name "Test credentials":

 

var credentialRecord = new GlideRecord('discovery_credentials');
credentialRecord.addQuery('name', 'Test credentials');
credentialRecord.query();
if (credentialRecord.next()) {
    var credentialSysID = credentialRecord.sys_id;
    var provider = new sn_cc.StandardCredentialsProvider();
    var credentials = provider.getCredentialByID(credentialSysID);
    gs.info("User name: " + credentials.getAttribute("user_name"));
    gs.info("Password: " + credentials.getAttribute("password"));
}