web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,075
I have the same question (0)
  • bkenn003 Profile Picture
    10 on at
    RE: Code to redirect a User To Specific Page After Login To Dynamics 365 Portal is not working

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

  • cloflyMao Profile Picture
    25,210 on at
    RE: Code to redirect a User To Specific Page After Login To Dynamics 365 Portal is not working

    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

  • Inkey Solutions Profile Picture
    2,075 on at
    RE: Code to redirect a User To Specific Page After Login To Dynamics 365 Portal is not working
    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?
  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Code to redirect a User To Specific Page After Login To Dynamics 365 Portal is not working

    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

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 128

#2
DAnny3211 Profile Picture

DAnny3211 126

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans