web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Code to redirect a User To Specific Page After Login To Dynamics 365 Portal is not working

(0) ShareShare
ReportReport
Posted on by 2,100
I have the same question (0)
  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Partner,

    Prerequisite: make sure a test code could run on Home page.

    You could try code below on your Home page.

    var username = $('.username').text();
    if (username != "") {
      if (username == "Alejandro Pomeroy12") {
        if (localStorage.getItem('status') == null) {
          localStorage.setItem('status', 'logged');
          window.location.href = "/test";
        }
      }
    } else {
      localStorage.removeItem('status');
    }

    That's because if a user sign in portal, then his/her name will display on top right corner,

    pastedimage1573634762083v1.png

    then we could grab text of the element as condition to check whether user has logged.

    Process is below:

    1.1 If guest -> do nothing(remove localstorage item)

    1.2 If user has logged out -> remove localstorage item(to make user could still be redirected if he sign in again)

    2.1 If user value not equals a specific value, do nothing.

    2.2 If user value equals a specific value, then go to next step

    3. The first time when user enters Home page, "status" item not exists, then we add the item and redirect user to page.

    4. When user navigates back to Home page, due to the item has been added, so we do nothing for him.

    5. When user logged out, then back to 1.2

    In addition, the code only works when you enter sign in page from home page because we only add it to Home web template;

    you could move it to header to test whether it could work for all pages.

    Regards,

    Clofly

  • Inkey Solutions Profile Picture
    2,100 on at
    Hello Clofly Mao,
    Thank you for the response. You saved my day. It worked like a charm. 
    One more question, can I check the web portal user role in the webpage using the custom script as I require to run this only for the Admin role?
  • cloflyMao Profile Picture
    25,210 on at

    Hi Partner,

    Try to assign user role to a temp liquid variable, then give the value to js variable.

    pastedimage1573728504338v2.png

    pastedimage1573728466791v1.png

    If above steps could work, then make modification.

    Regards,

    Clofly

  • bkenn003 Profile Picture
    10 on at

    What if it is based on user role not the name on text?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans