Mention height and width in Percentage instead of Pixels – Modal Popups in Dynamics 365 CE – NavigateTo

Hi Everyone,

Today a bug was created by the user saying the popup window is too small and we were using below code to show the HTML Webresource as a popup.

var pageInput = { pageType: "webresource", webresourceName: "WebResourceName" };
        var navigationOptions = {
            target: 2,
            width: 400,
            height: 300,
            position: 1
        };
        Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
            function success() {
                // Handle dialog closed
            },
            function error() {
                // Handle errors
            }
        );

When we have checked the code was working fine and able to see the window normally. After some checks with the users came to know that User has 19 inches monitor and that has opened doors to fix the issue. We all know that we have to use percentage instead of pixels for height and width and here is the way to use the same in NavigationOptions of NavigateTo function.

Here is the modified code of the same.

var pageInput = { pageType: "webresource", webresourceName: "WebResourceName" };
        var navigationOptions = {
            target: 2,
            //width: 400,
            //height: 300,
            width: { value: 90, unit: "%" },
            height: { value: 90, unit: "%" },
            position: 1
        };
        Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(
            function success() {
                // Handle dialog closed
            },
            function error() {
                // Handle errors
            }
        );

Hope this helps.


Happy 365’ing
Gopinath

addOnLookupTagClick event in Dynamics 365 Release Wave 1 2020 – Restrict lookup record opening

Hi Everyone,

I was just going through Microsoft Docs to understand the new features that were released in Dynamics 365 Release Wave 1 2020 and found a new event introduced for lookups and I feel it is quite useful.

While working many of our customers might have clicked on a lookup value by mistake and the system might have redirected them to lookup record by loosing existing context of the working record.

By using this addOnLookupTagClick event, we can control that. Here is the peice of the code for the same. Just put this code on the load event.

function onLoadOfCase(executionContext) {
    var formContext = executionContext.getFormContext();
    formContext.getControl('customerid').addOnLookupTagClick(function (e) {
        e.getEventArgs().preventDefault(); // disables the default behaviour of opening the record
        // Get the lookup record 
        var lookupRecord = e.getEventArgs().getTagValue();
    });
}

The above code will prevent opening the lookup record when clicked. However if you want to open a record, we can use NavigateTo API and open the lookup record as a popup without disturbing/loosing the current context.

Here is the piece of the code for the same.

function onLoadOfCase(executionContext) {
    var formContext = executionContext.getFormContext();
    formContext.getControl('customerid').addOnLookupTagClick(function (e) {
        e.getEventArgs().preventDefault(); // disables the default behaviour of opening the record
        // Get the lookup record 
        var lookupRecord = e.getEventArgs().getTagValue();
        // Open lookup record as a popup.
        Xrm.Navigation.navigateTo({
            pageType: "entityrecord",
            entityName: lookupRecord.entityType,
            formType: 2, // Only Edit Mode is supported now. 
            entityId: lookupRecord.id
        }, {
            target: 2,
            position: 1,
            width: 900,
            height: 600
        });
    });
}

Hope this helps.


Happy 365’ing
Gopinath