How to access credential using javascript?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2018 05:55 AM
Hi, Guys. I'm new in servicenow workflow and script includes module, I'm doing an api integration wherein I would like to input the credential(api key, username, password) in javascript but I don't want my credential become viewable by other user. I saw a credential module in servicenow. Is it possible to access it in script includes(javascript)? If no, I would like to know if there's an other way to do it.
Thanks in advance!
Sev.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2018 02:43 PM
You can create a rest message and use Basic Auth Profile or if you just want to store the credentials, you can store it in sys_auth_profile_basic and use
setBasicAuth
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2018 02:49 PM
In addition to what Sanjiv suggests, another option is custom system properties. You can store each element as a separate system property and set type as password2 so the value gets encrypted. Then in your script you can use gs.getProperty(“property-name”) to get its value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 02:12 AM
Hi, Michael. Thanks for your suggestion. Currently I'm still try to search on how to do your suggestion("another option is custom system properties. You can store each element as a separate system property". I'm not yet familiar to it. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2018 06:37 AM
Here is an article describing how to create a system property:
Since you want your password and key hashed, make sure you choose type of Password2 as that will encrypt the value and not show it to any users. Once you create your properties you can also add it as a module in the application navigator and bucket them in a "Category Property". Navigate to System Properties \ Categories (its at bottom of list), and click new and then link your new properties.
Once added you can add this to the application navigator with in your integration "app" and show a nice list of properties. Please see "Create a properties module" section in this article or the TechNow espisode:
Then to get the value of your property use this in your script:
var masterPassword = gs.getProperty("PASSWORD-PROPERTY-NAME");
Please mark this post or any as helpful or the correct answer to your question if applicable so others viewing can benefit.