can we restrict portal access for a user using theme and ui script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 03:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2024 03:31 PM
Hi @dk10 ,
1. Let us assume the Portal for you is "/sp". I will show all the next steps for /sp but you can have your own portal.
2. Create a UI script as "runOnLoad" as below:
Global: false
Active: true
//Check if you are on the login page, on then run it
if(window.location.href.toString().indexOf("sp") > -1)// Replace sp with your portalurl name
{
try{
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1+
var isChrome = !!window.chrome && !!window.chrome.webstore;
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;
var output = 'Detecting browsers by ducktyping:<hr>';
output += 'isFirefox: ' + isFirefox + '<br>';
output += 'isChrome: ' + isChrome + '<br>';
output += 'isOpera: ' + isOpera + '<br>';
output += 'isIE: ' + isIE + '<br>';
output += 'isEdge: ' + isEdge + '<br>';
output += 'isBlink: ' + isBlink + '<br>';
//alert(output);
if(isIE){
alert("IE is not the best place to be!!!! 😛 :D");
//write the next code based on your needs
}
}
catch(e){
alert(e.toString());
}
}
3. Now you are done with the UI script but it will not work in Service Portal as it is.
4. To Include it in Service Portal, go to the portal record and go to the theme as shown below:
5. Go to the related list at the bottom of the theme form and go to JS includes --> NEW
6. On the form give any display name and the
Source: UI script
UI script: runOnLoad -- the name of the UI script.
You are done!!!!
Result:
NOTE: I am sure, you will update the code on the UI script later but keep in mind one thing for sure. Everytime you are making the change to the UI script, make sure you change the UI script name and save it for example:
First time when you save it : runOnLoad
Save it second time.... runOnLoad1
Save it third time...runOnLoad2... you wish but the name should differ or else you would not see the changes happening immediately on the portal
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda