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 365 | Integration, Dataverse...
Answered

Open Lookup Record in New Window

(4) ShareShare
ReportReport
Posted on by 317
Is there a way to open a lookup record in a new window without having to create a button in the ribbon or doing a keyboard command? 
 
The only option I can think of is creating a new field that calls .js on change and open it. 
 
 
Ideally, I'd like to call .js on click of the lookup field but I dont see that as an option. 
 
Thanks! 
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    300,917 Super User 2025 Season 2 on at
    Can you tell us what Dynamics 365 application this question is related to? There are several different solutions in the Dynamics 365 family, like Sales, Finance, Supply Chain Management, Project Operations, and Business Central. 
    As you posted your question in the Dynamics 365 General forum without too much of details, we aren't able to know what product you are using.
  • nvrhughes Profile Picture
    317 on at
    Sales App. I posted in general because this is in regards to any look up field in Dynamics. Thanks! 
  • Verified answer
    Daivat Vartak (v-9davar) Profile Picture
    7,835 Super User 2025 Season 2 on at
    Hello nvrhughes,
     

    You've correctly identified the limitations of directly triggering JavaScript on the click of a standard lookup field in Dynamics 365. Out-of-the-box, there isn't a direct "On Click" event available for lookup controls that you can hook JavaScript to.

    Your idea of creating a new field that triggers JavaScript on change is a viable workaround, but it requires an extra field on the form and might not be the most intuitive user experience.

    Here are a few alternative approaches and considerations, ranging from more straightforward to slightly more involved:

    1. Leveraging the "Open Associated Records" Behavior (Configuration-Based - Limited Control):

    While not a new window, you can configure the behavior of the lookup to open associated records in a new tab within the Dynamics 365 Unified Interface. This might be acceptable depending on your user's workflow.

    • Go to Settings > Customization > Customize the System.

    • Expand Entities and select the entity containing your lookup field.

    • Expand 1:N Relationships (if it's a lookup to a related entity) or N:1 Relationships (if the lookup is on this entity).

    • Find the relationship corresponding to your lookup field.

    • In the relationship definition, look for the "Navigation Pane Item" section (for related entities) or the "Behavior" section (for N:1 relationships).

    • For some relationship behaviors (like "Referential"), you might have options related to how associated records are opened. Experiment with these settings (in a non-production environment first) to see if any achieve a new tab behavior that suits your needs.

    •  

    Limitations of this approach:

    • Limited control over whether it's a new tab or a new window.

    • Behavior might vary depending on the relationship type and configuration options available.

    • Doesn't allow for custom JavaScript execution before opening.

    •  

     

    2. Creating a Custom Control (PCFs - More Involved, but Flexible):

    This is the most flexible approach but requires development skills. You could create a Power Apps component framework (PCF) control that mimics the appearance of a standard lookup but provides a custom click event.

    • Develop a PCF Control: This control would:

      • Render a UI similar to the standard lookup.

      • Handle the click event on the rendered lookup element.

      • Retrieve the selected record's ID and entity type.

      • Use Xrm.Navigation.openForm() with the windowOptions parameter to open the record in a new window. 

    • Add the PCF Control to Your Form: Replace the standard lookup field on your form with your custom PCF control.

       

     

    Advantages of this approach:

    • Full control over the click behavior.

    • Ability to execute custom JavaScript before opening the new window.

    • Provides a seamless user experience if the PCF control is designed well.

     

    Disadvantages of this approach:


    • Requires development expertise in PCF.

    • More time and effort to implement.


    •  

    3. Modifying the Ribbon (Less Ideal for Direct Lookup Click):

    While you mentioned avoiding ribbon buttons, it's worth noting that you could add a button next to the lookup field that, when clicked, retrieves the lookup value and opens it in a new window using Xrm.Navigation.openForm() with windowOptions. However, this doesn't achieve the goal of clicking directly on the lookup.

     

    4. Exploring Browser Extensions (Client-Side, Not Recommended for Managed Solutions):

    Technically, a browser extension could potentially intercept clicks on lookup fields and trigger a new window. However, this is a client-side solution that is:

    • Not part of your Dynamics 365 application: It would rely on users installing a specific browser extension.

    • Difficult to manage and support: Ensuring all users have the extension and it works consistently can be challenging.

    • Potentially impacted by Dynamics 365 updates: Changes to the Dynamics 365 UI could break the extension.

    • Not a recommended approach for managed solutions or enterprise deployments.

    •  

     

    Back to Your ".js on change" Idea:

    If you want a less development-intensive approach than a PCF, your idea of using an additional field with an OnChange event could work, albeit with a slightly different user interaction:

    • Add a New Single Line of Text Field: Place this field visually near your lookup field. You could even style it to look like a button or an icon.

    • Add JavaScript OnChange Event: On the OnChange event of this new field:

      • Retrieve the value (ID) from your primary lookup field.

      • Open the lookup record in a new window using Xrm.Navigation.openForm() with windowOptions.

      • Optionally, clear the value of this trigger field after opening to allow for subsequent clicks. 

    • Guide Users: Instruct users to click on this new "button-like" field to open the related record in a new window.

    •  

     

    Example of the ".js on change" Approach:

    function openLookupInNewWindow(executionContext) {
        var formContext = executionContext.getFormContext();
        var lookupField = formContext.getAttribute("your_lookup_field_name"); // Replace with your lookup field schema name
        var triggerField = formContext.getAttribute("your_trigger_field_name"); // Replace with your new trigger field schema name
        if (triggerField.getValue()) { // Check if the trigger field has a value (i.e., was "clicked")
            var lookupValue = lookupField.getValue();
            if (lookupValue && lookupValue.length > 0) {
                var recordId = lookupValue[0].id;
                var entityName = lookupValue[0].entityType;
                var windowOptions = {
                    openInNewWindow: true
                };
                Xrm.Navigation.openForm({
                    entityName: entityName,
                    entityId: recordId
                }, windowOptions);
            }
            triggerField.setValue(null); // Clear the trigger field after opening
        }
    }

    You would then associate this JavaScript function with the OnChange event of your newly created trigger field. Users would need to "click" (enter and exit, or somehow trigger the change event) on this field to open the lookup record. You might need to visually style this trigger field to make it clear to the user what its purpose is.

     

    Recommendation:

    The PCF control approach offers the most seamless and direct way to achieve the desired "on click" behavior with a new window, but it requires development effort.

    The "new field with .js on change" approach is a more accessible workaround if you want to avoid code development, but it involves an extra UI element and a slightly less intuitive user interaction.

    The "Open Associated Records" behavior is worth exploring if a new tab is acceptable, as it's configuration-based.

    Ultimately, the best approach depends on your technical resources, the level of customization required, and the desired user experience.

     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans