How to pass current user's username and password to REST Message as a parameters?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 02:38 AM
Hello Team,
I have a requirement to export the list of data into Excel and open directly in Google Sheets. For that we have created a context menu, script include, flow designer and REST Message.
We are calling the REST Message from the flow designer and changing the Endpoint value (to current browser URL of the list) of the REST message dynamically to utilize the URL export.
If I give basic authentication profile with my username and password in REST Message, then it is working as expected for me. But if any other user tries to utilize the export functionality it is not working.
Anyone know how to get username and password of the user when they clicks the "Export" button from the context menu and sent to the REST Message we are calling as a parameter?
Thanks,
Dhanakoddi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 02:40 AM
Hi @DhanakoddiT ,
Refer below code to authenticate any user to use export functionality & modify your code accordingly:
var user = gs.getUser();
var username = user.getUserName();
var password = gs.getSessionToken();
// Pass username and password to your REST Message as parameters
// Example:
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod("Your Method");
restMessage.setEndpoint("Your Endpoint");
restMessage.setRequestHeader("Authorization", "Basic " + GlideStringUtil.base64Encode(username + ":" + password));
// Send the REST Message
var response = restMessage.execute();
If you find my response helpful, please consider selecting "Accept as Solution" and "Helpful" .
Thanks,
Anusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 03:30 AM
Hello Anusha,
Thanks for the script.
I am calling the REST Method from the flow designer. So I am trying to get the userID and Session details from the context menu itself and passing to flow designer using Script Include.
But I am unable to get the session details using gs.getSessionToken(); line from the context menu. Could you please tell me how we can get it from client side?
Thanks,
Dhanakoddi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 09:04 AM
Hello @Anusha Reddy VK ,
Thanks for the script.
I am calling REST Message from the flow designer. Could you please tell me how to get the session token from the context menu (client side) and pass it to the flow designer using script include.
Thanks,
Dhanakoddi