Is it possible to set Homepage is different based on users/Groups/roles?

akin9
Tera Contributor

Hello All

Is it possible to keep Homepage is different based on users/Groups/roles

Requirements

We want to set login home page as one of our workspace page for particular groups of users.

Remaining as usual 

We have created a user preference but its working for all,

tried multiple methods but no luck.

Please support to achieve this it will be grateful

its an urgent requirement but no luck i want to know its possible or not?.

9 REPLIES 9

@akin9 You have added only one routing page here with audiences. Where have you mentioned for 'Admins' or 'Non-Admins' or 'Itil' roles etc? 

 

Did you try to add two records of different audiences here with different order? 

 

Note: I'm asking based on the screenshot here. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Hi @Sujatha V M 

We want to set  only "XX" role users to login home page is workspace remaining all users login page is same as UI Dashboard view based on the "glide.login.home" property.

Can we achieve this?

 

Sid_Takali
Kilo Patron
Kilo Patron

akin9
Tera Contributor

Hi @Sid_Takali 

Thank you for the Quick reply

We done the same but no luck.

If we can achieve this by the "SPEntryPage" script include?

akin9
Tera Contributor

Hello @Sujatha V M @Ankur Bawiskar @saurab @Community Alums @Tai Vu @anders1 and experts

Please confirm is it really possible and support it will be great to me.Thanks!

I have tried multiple methods but no luck.

Finally done modification on the

OOB "SPEntry page" script include but not working can you pls correct me if wrong!

 

Added below code on the "getFirstPage" function in below.

 

var SPEntryPage = Class.create();

SPEntryPage.prototype = {

    initialize: function() {
        this.logVariables = false; // for debugging 
        this.portal = this.getDefaultPortal(); // The URL suffix for default portal
    },

    /***
     *
     * Fetch the default portal suffix
     *
     **/
    getDefaultPortal: function() {
        var gr = new GlideRecord("sp_portal");
        gr.addQuery("default", true);
        gr.query();
        if (gr.next())
            return "/" + gr.getValue("url_suffix") + "/";

        return "/esc/";
    },
    /***
     *
     * Referred to by property: glide.entry.page.script
     * 
     **/
    getLoginURL: function() {
        // When requesting a page directly (eg: /problem_list.do)
        // The platform session_timeout.do sets the login page to welcome.do
        // Since we are handling the login, clear that value
        var session = gs.getSession();
        var nt = session.getProperty("nav_to");
        var sPage = session.getProperty("starting_page");
        if (nt == "welcome.do")
            session.clearProperty("nav_to");

        if (!sPage && !nt)
            session.putProperty("starting_page", gs.getProperty("glide.login.home"));

        // Send the user to the portal's login page
        var portalGR = new GlideRecord("sp_portal");
        portalGR.addQuery("url_suffix", this.portal.replace(/\//g, ""));
        portalGR.addNotNullQuery("login_page");
        portalGR.query();
        if (portalGR.next())
            return this.portal + "?id=" + portalGR.login_page.id;

        // Send to the a default login page
        return this.portal + "?id=login";
    },

    /***
     *
     * Referred to by property: glide.entry.first.page.script
     * 
     **/
    getFirstPageURL: function() {
        var session = gs.getSession();
        this.logProperties('before', session);
		
		// Check if user has the "XXX" role
      var userRoles = gs.getUser().getRoles();
    if (userRoles && userRoles.indexOf('XXX') != -1) {
        // Redirect user with "xxx" role to specific URL
        return "workspace url";
	}
        // has roles and is not a Service Portal page - go to UI16
        var nt = session.getProperty("nav_to");
        var isServicePortalURL = new GlideSPScriptable().isServicePortalURL(nt);
        var redirectURL = session.getProperty("login_redirect");

        if (user.hasRoles() && !redirectURL && !isServicePortalURL)
            return;

        // user may have logged in from a frame, the /login_redirect.do page will bust out of it
        if (!redirectURL) {
            // redirectURL is nav_to 
            // if nav_to == "welcome.do" then use starting_page
            var sPage = session.getProperty("starting_page");
            if (sPage && nt == "welcome.do")
                nt = sPage;

            // Avoid a redirect loop to the home page
            var ep = gs.getProperty("glide.login.home");
            if (nt) {
                if (ep == nt)
                    nt = null;
            }
            // PRB726860: if page is still welcome.do, go to glide.login.home preserving frameset
            if (nt == "welcome.do") {
                session.putProperty("nav_to", ep);
                return;
            }

            session.putProperty("login_redirect", nt || "true");
            return "/login_redirect.do?sysparm_stack=no";
        }

        session.clearProperty("login_redirect");
        session.clearProperty("nav_to");
        var returnUrl = this.portal;
        if (redirectURL && redirectURL != "true") {
            var spUrl = new GlideSPScriptable().mapUrlToSPUrl(redirectURL);
            returnUrl = spUrl ? this.portal + "?" + spUrl : redirectURL;
            if (!user.hasRoles() && !spUrl && redirectURL.indexOf("home_splash.do") > -1)
				returnUrl = this.portal;
        }

        this.logProperties('after', session);
        if (!this.logVariables) {
            gs.log('redirectURL: ' + redirectURL);
            gs.log('User: ' + user.getName());
            gs.log('is internal: ' + (!user.hasRoles()));
            gs.log('returnUrl: ' + returnUrl);
        }

        return returnUrl;
    },

    logProperties: function(beforeOrAfter, session) {
        if (!this.logVariables)
            return;

        gs.log('SPEntryPage: Redirect ------------------------------- ' + beforeOrAfter);
        gs.log('session.starting_page: ' + session.getProperty("starting_page"));
        gs.log('session.nav_to: ' + session.getProperty("nav_to"));
        gs.log('session.login_redirect: ' + session.getProperty("login_redirect"));
        gs.log('gs.fURI: ' + session.getURI());
    },

    type: 'SPEntryPage'
};