Scott17 Posted September 6, 2018 Report Share Posted September 6, 2018 I am wondering if there is a way to redirect users to another webpage based on the role of the logged in user. I currently have this working when a user logs in for the first time and I pasted that script below. <script> if ("[@authfield:Users_tbl_Role]" == "Manager"){ window.location="https://website.com/manager-portal"; } else{ window.location="https://website.com/regular-portal"; } </script> I want to use this same funcionality on search results page of some of my data pages. The data pages currently have an HTML block that is an a href hyperlink that redirect the user to "customer profiles" and accepts parameters to do so. However, my manager users and regular users need to be redirected to different webpages. Is it possible to have hyperlinks redirect to different webpages based on the roles of the user signed in? I have also tried to use a button instead of a hyperlink with a similar script above to execute onClick, however, I have not been able to get that right. I appreciate any suggestions! This functionality would allow me to use less data pages and thus make it simpler for me to make updates to only one data page that works for all users rather than making the same updates to several similar data pages like I currently am. Quote Link to comment Share on other sites More sharing options...
IamGroot Posted September 7, 2018 Report Share Posted September 7, 2018 Hello @Scott17 Try this code for your Hyperlink in HTML Block: <div id="link"></div> <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { if ("[@authfield:Users_tbl_Role]" == "Manager") { document.getElementById("link").innerHTML='<a href="https://website.com/manager-portal">Manager Portal</a>'; } else{ document.getElementById("link").innerHTML='<a href="https://website.com/regular-portal">Regular Portal</a>';} }); </script> I hope this helps. Quote Link to comment Share on other sites More sharing options...
Scott17 Posted September 7, 2018 Author Report Share Posted September 7, 2018 17 hours ago, IamGroot said: Hello @Scott17 Try this code for your Hyperlink in HTML Block: <div id="link"></div> <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { if ("[@authfield:Users_tbl_Role]" == "Manager") { document.getElementById("link").innerHTML='<a href="https://website.com/manager-portal">Manager Portal</a>'; } else{ document.getElementById("link").innerHTML='<a href="https://website.com/regular-portal">Regular Portal</a>';} }); </script> I hope this helps. Hi @IamGroot , Thank you for the suggestion! I gave it a try while signed in as a manager and what is happening is the first line is showing "Regular Portal" with a hyperlink to "https://website.com/regular-portal". It should be "Manager Portal" linked to "https://website.com/manager-portal" since I am signed in as a manager. Also, the link is only showing up on the first line of results and nothing is showing up for the other lines. Any ideas how to resolve that? Thank you! Quote Link to comment Share on other sites More sharing options...
IamGroot Posted September 7, 2018 Report Share Posted September 7, 2018 Hi @Scott17 Sorry I made a miscalculation, because I tested it with single record so I thought that it was working. My initial assumption is we need to add a JavaScript LOOP code for it. Let me get back to you as soon as I get the right code to it. Thanks ! Quote Link to comment Share on other sites More sharing options...
Scott17 Posted September 10, 2018 Author Report Share Posted September 10, 2018 Hi @IamGroot No worries at all, I appreciate your help! Quote Link to comment Share on other sites More sharing options...
IamGroot Posted September 10, 2018 Report Share Posted September 10, 2018 Hi @Scott17 I have found another solution for this issue without using any JavaScript code. And this is the easiest one by using only the Standard features of Caspio. Just follow this following steps: 1. Create a Formula field to your User table. 2. Insert this code to the formula field: Quote CASE WHEN [@field:Users_tbl_Role] ='Manager' THEN 'https://website.com/manager-portal' ELSE 'https://website.com/regular-portal' END 3. In your DataPage, include the formula field in your "Result's Page" and select URL link in "Render value as". You can also change the label display of the link by checking the "Enable custom display". 4. Hit "Finish" and test it. I hope this helps Quote Link to comment Share on other sites More sharing options...
Scott17 Posted September 10, 2018 Author Report Share Posted September 10, 2018 Hi @IamGroot I see how that would work, I still have a problem though and this is my fault for not providing enough information in my original post (sorry about that! I appreciate all your help!). The table that is being used in the datapage is not the user's table that stores the user's role. It is another table holding information on customers information (the hyperlink will go to different versions of the customer profile depending on if the user is a manager or not). So right now, I have two data pages that essentially do the exact same thing except the hyperlinks that are inserted in HTML blocks are different. For example: <a href=" https://website.com/manager-portal/?cid=[@field:Client_ID]&fn=[@field:Client_1_First_Name]&ln=[@field:Client_1_Last_Name]">View Profile</a> <a href=" https://website.com/regular-portal/?cid=[@field:Client_ID]&fn=[@field:Client_1_First_Name]&ln=[@field:Client_1_Last_Name]">View Profile</a> Do you think there is a way to use Caspios standard features for this situation? Or do you think there is some JS code that can still be used? Thanks again for all your help! Quote Link to comment Share on other sites More sharing options...
IamGroot Posted September 10, 2018 Report Share Posted September 10, 2018 1 hour ago, Scott17 said: Hi @IamGroot I see how that would work, I still have a problem though and this is my fault for not providing enough information in my original post (sorry about that! I appreciate all your help!). The table that is being used in the datapage is not the user's table that stores the user's role. It is another table holding information on customers information (the hyperlink will go to different versions of the customer profile depending on if the user is a manager or not). So right now, I have two data pages that essentially do the exact same thing except the hyperlinks that are inserted in HTML blocks are different. For example: <a href=" https://website.com/manager-portal/?cid=[@field:Client_ID]&fn=[@field:Client_1_First_Name]&ln=[@field:Client_1_Last_Name]">View Profile</a> <a href=" https://website.com/regular-portal/?cid=[@field:Client_ID]&fn=[@field:Client_1_First_Name]&ln=[@field:Client_1_Last_Name]">View Profile</a> Do you think there is a way to use Caspios standard features for this situation? Or do you think there is some JS code that can still be used? Thanks again for all your help! Hi @Scott17, Your welcome ! I would love to help you, but first can you provide the steps in this process (for example: When user logs he needs to see this Data -> when he click the link in the result he needs to go to this DataPage -> the next DataPage should received the paramameter ..... and so on). And for me to better understand the problem, Can I also ask for the DataPage URL or WebPage? Thanks. Quote Link to comment Share on other sites More sharing options...
Scott17 Posted September 11, 2018 Author Report Share Posted September 11, 2018 Hi @IamGroot' I just sent you a message with the details you asked for. Thank so much! Quote Link to comment Share on other sites More sharing options...
IamGroot Posted September 11, 2018 Report Share Posted September 11, 2018 Thank you @Scott17 I will look up to it, and get back to you as soon as I found a resolution Quote Link to comment Share on other sites More sharing options...
Scott17 Posted September 11, 2018 Author Report Share Posted September 11, 2018 Thanks again @IamGroot! Quote Link to comment Share on other sites More sharing options...
Kronos Posted October 20, 2023 Report Share Posted October 20, 2023 Hi, if you want to redirect users if they are using mobile or desktop you may try this solution: I hope this helps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.