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 :
Microsoft Dynamics CRM (Archived)

Using javascript to go to main entity view

(0) ShareShare
ReportReport
Posted on by 3,079

I have javascript that we run on a button click that does a series of things (including running an action, etc...).  Once it's done, if it's successful, I would like to close the record and go to the view page of the entity.  I've found that I can use "Xrm.Page.ui.close()", but that just goes back to whatever page they were on before they opened the record.  So if they were on the view page, that's fine, but if they were on a different record, it goes back to that other record.

I know there's the Xrm.Utility.OpenEntityForm, but I can only see how to use that to either go to a specific record or create a new record, not to go to the view page.  And I tried even just window.open (using a URL in the format https://<site>/<org>/main.aspx?etn=<entity_name>&pageType=EntityList&web=true), which goes to what I want but it opens it in a new tab.  If I add "self" in as the second parameter, it does nothing.  window.location.href does nothing.

How can I have this function end by closing the record and going to the entity view?  I've got to be missing something...

*This post is locked for comments

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You can navigate to any page by using the following code as you mentioned above:

    org.crm.dynamics.com/main.aspx;pagetype=entitylist

    If you need to get to that page from where you are, you can use:

    window.location.href = targetUrl;

    window.navigate(targetUrl);

    One of those should work.

    Are you getting any errors when you use window.location.href.

    Do you know if it hits that line of code, or if you go to debugger (F12), do you see any errors under console or in debugger window?

  • awalters Profile Picture
    3,079 on at

    I'm not getting any errors with window.location.href, no.  I can see in the debugger that it hits it, and then just keeps going to the next line.  Nothing happens in the current window.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Can you try window.navigate?

  • awalters Profile Picture
    3,079 on at

    I get "window.navigate is not a function".

    ETA: I get that in Chrome and FF, which are the browsers I care about.  :-)  In IE, I don't get an error, but it still doesn't do anything.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    There are a couple of things that maybe you can try:

    1. After calling window.location.href = ??, call window.location.reload(true);

    2. Try calling window.location.replace(targetUrl) instead of window.location.href

    3. Try calling parent.window.location.href = ?? Some things changed in 2016+

    Let me know if any of these worked.

  • VermaNitin Profile Picture
    455 on at

    Hi,

    Can you please try the below code and let me know if it works?

    window.location="https://<site>/<org>/main.aspx?etn=<entity_name>&pageType=EntityList&web=true"

    Hope it helps!

    Many thanks,

    Nitin Verma

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    The issue you are facing is because Dynamics CRM has lots and lots of iFrames and they mess with standard javascript function.

    window.location.href = "url";  works but you just don't see that happening on UI.

    To understand what I am saying try parent.window.location.href. = "url";

    Solution for your issue will be to use

    window.top.location.href = "url";

    Hope that will help you with your problem.

  • awalters Profile Picture
    3,079 on at
    window.top.location.href = "url" did it.  Thank you!

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans