How retrieve password stored as credentials into script include

BartFrelian1337
Tera Contributor

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:

 

-------------------


// Retrieve API Key from Credentials table using GlideCredentialUtility
var apiKey = new GlideCredentialUtility().getPassword(credentialSysId);
 
var apiUrl = baseUrl + functionName + "?code=" + apiKey;
 
gs.info(apiUrl);
 
This gives me following exception:
 
com.glide.script.RhinoEcmaError: "GlideCredentialUtility" is not defined.
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
 
Do you have experience in such a usecase how to securely retrieve value stored in the Credentials table into Script Include?
 
Any help will be appreciated!
 
Thanks
Bart.
 
 
4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@BartFrelian1337 

check this

Outbound REST Message and client credentials 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur this sounds like an interesting work around but it requires creating rest message to store the API Key for script include that will be triggered by business rule to make call to get the token first then use that token to perform one more api call to third party endpoint. I would ideally limit my configuration to one business rule executing the script include that can access the credentials record. I will keep this in mind though in case i cannot figure another way around.

@BartFrelian1337 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

BartFrelian1337
Tera Contributor

I went to use a sys_properties table that supports 2way encrypted password but part of my brain still wonders if it is possible to extract value for credential store into the Script Include.

I am aware that the easiest approach would be to create Rest Message however in my case it won't solve my business problem. The application i am building will store multiple keys related to multiple environments. I need to create a central spaces where users store environments record then tight them up to the stored credential without needing to know how to build a rest message.