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 :
Power Pages - General Discussions
Suggested answer

Switch views in modal for lookup field

(1) ShareShare
ReportReport
Posted on by
Currently I got a requirement related to the D365 Portal and cannot work it out. In portal page, we have a lookup field Work Order and there are three views associated with it. When we click the magnifier and open the modal, we can see there are three options for the view in the dropdown box. When we clicking on a non-default one, the records list will be filtered and returned with the new view. How could I program it to automatically switch the view based on the value of another field called type? Thank you!
 
Categories:
I have the same question (0)
  • Suggested answer
    DP_Prabh Profile Picture
    21 on at
    Switch views in modal for lookup field

    Hi, you can achieve this by:

    • Identify the GUIDs of the views associated with the Work Order lookup that you want to switch between.
    • Map the type field values to these view GUIDs in your JavaScript code.
    • Use JavaScript to read the current value of the type field on the portal form.
    • Intercept the click event on the lookup magnifier icon for the Work Order field to prevent the default modal from opening.
    • Construct a custom lookup URL that includes the correct viewid parameter based on the type field’s value.
    • Open the lookup modal programmatically with this custom URL so that the records are filtered according to the selected view.
    • Replace any placeholder IDs/selectors in your code with the actual portal control IDs or CSS selectors.
    • Test thoroughly to ensure the modal opens correctly and switches views as expected for different type values.
    • Consider edge cases such as when type is empty or doesn’t match any mapped view (use a default view).
    • Optionally, if JavaScript customization is too complex, explore building custom pages or APIs to achieve similar functionality. 
  • Suggested answer
    Jon Unzueta Profile Picture
    1,213 Super User 2025 Season 2 on at
    Switch views in modal for lookup field
     

    You can achieve this by using JavaScript to:

    1. Detect changes in the Type field.
    2. Dynamically set the lookup view ID for the Work Order field before the modal opens.

    🔧 Steps to Implement

    1. Get the View IDs

    First, identify the GUIDs of the views associated with the Work Order lookup. You can find these in the Dataverse table view settings.

    2. Add JavaScript to the Portal Page

    You’ll need to inject JavaScript into the page using a Web Page Web File or directly in the Web Page’s Custom JavaScript section.

    Here’s a sample script:

    $(document).ready(function () {

        // Map Type values to View GUIDs

        var viewMap = {

            "Installation": "GUID_FOR_INSTALLATION_VIEW",

            "Maintenance": "GUID_FOR_MAINTENANCE_VIEW",

            "Inspection": "GUID_FOR_INSPECTION_VIEW"

        };

        // Watch for changes in the Type field

        $("#type_field_id").change(function () {

            var selectedType = $(this).val();

            var viewId = viewMap[selectedType];

            if (viewId) {

                // Set the view for the Work Order lookup

                $("#workorder_lookup_field_id").attr("data-viewid", viewId);

            }

        });

    });

    Replace #type_field_id and #workorder_lookup_field_id with the actual DOM IDs of your fields. You can inspect these using browser dev tools.

    🏷️ Tag me if you have any further questions or if the issue persists.

    ✅ Click "Accept as Solution" if my post helped resolve your issue—it helps others facing similar problems.

    ❤️ Give it a Like if you found the approach useful in any way.

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…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#2
Lucas001 Profile Picture

Lucas001 48 Super User 2025 Season 2

#3
KevinGador Profile Picture

KevinGador 44 Super User 2025 Season 2