
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 01:27 PM - edited 08-11-2023 07:05 AM
I have a script that pulls in a set of credentials to create a payload for another server. In the workflow, it will sometimes not get the username value from the credential store. I'm unable to replicate it in a sub-prod instance, but it errors out saying it cannot convert a null value to an object.
var credentialId = 'sys_idForCredentials';
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID(credentialId);
var username = credentials.getAttribute("user_name");
var password = credentials.getAttribute("password");
Has anyone experienced this and if so, how did you solve for it not always pulling the attribute?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 04:59 PM
can you please try below script -
try {
var credentialId = '1ba91ceb1bffd950b7b35284604bcb12';
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID(credentialId);
var username = credentials.getAttribute("user_name");
var password = credentials.getAttribute("password");
// Proceed with payload creation using username and password
} catch (ex) {
gs.error("Error retrieving credentials: " + ex.message);
} finally {
// Close any open connections
}
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 04:59 PM
can you please try below script -
try {
var credentialId = '1ba91ceb1bffd950b7b35284604bcb12';
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID(credentialId);
var username = credentials.getAttribute("user_name");
var password = credentials.getAttribute("password");
// Proceed with payload creation using username and password
} catch (ex) {
gs.error("Error retrieving credentials: " + ex.message);
} finally {
// Close any open connections
}
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2024 04:11 AM
That's not the solution to the problem!
To avoid the evaluator error, the script can be changed like this:
var credentialId = '1ba91ceb1bffd950b7b35284604bcb12';
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID(credentialId);
if (credentials != null)
{
var username = credentials.getAttribute("user_name");
var password = credentials.getAttribute("password");
}
However, this does not solve the underlying problem that getCredentialByID() does not deliver an existing credential (e.g. if the script is invoked by a non-admin user?)
So, how to ensure that the credential can be loaded?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 12:20 PM
That's our current problem, in that the getCredentialByID() doesn't consistently work. Any idea how to resolve that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 04:03 AM
This may help to fix the issue:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783632
Not a good solution, but it works!