Skip to Main Content

There are times, where you may have forgotten the password of an email account used in ServiceNow. Fortunately, passwords are usually stored in a field type "Password (2 Way Encrypted)" which means we are able to retrieve it as plain text.

Let's have a look to get our information from an email account in ServiceNow:

var gr = new GlideRecord('sys_email_account');
gr.get('050be3881b04381047264375cc4bcb0d');'password')); // *************************; // *************************'password')); // +quYCHDWUvaa2Y3P1ntn/Q==

You see the following output because the function  getDisplayValue() returns the value replaced with asterisks and the function  getValue()  returns the password as an encoded value.

We can use one of ServiceNow's out of the box classes called GlideEncrypter to decrypt the password:

var encr = new GlideEncrypter();"Decrypted string = " + encr.decrypt(gr.getValue('password'))); // expertsnow


If you want to set the password through code execution, you have to be careful when doing this. By using the function  setValue() , the password will be set as plaintext into the field:

gr.setValue('password', 'expertsnow');'password')); // expertsnow


To set the password correctly as an encode value, use the function setDisplayValue() :

gr.setDisplayValue('password','expertsnow');'password')); // +quYCHDWUvaa2Y3P1ntn/Q==