Side Pane in D365/ Side Pane in Entity Form In D365

Side Pane in D365

In Account Entity Form we are showing the Account Related Contact in Side Pane using HTML Page.

We need to call JavaScript Function(APY.Account.LoadPromotions) on Different Event Like OnLoad, OnChange, OnSave Or Ribbion Button Click.

In this Blog I have registered the Event on OnLoad of Form with APY.Account.LoadPromotions


  • Create a Java script Webresource with below Code :

//Build test script comment

var APY = APY || { namespace: true };

APY.Account = APY.Account || { namespace: true };

APY.Account.LoadPromotions = function (executionContext) {

    "use strict";

    try {

        var formContext = executionContext.getFormContext();

        var qs = "accountid=" + formContext.data.entity.getId().replace('{', '').replace('}', '');

        Xrm.App.sidePanes.createPane({

            title: "Contacts",

            paneId: "ContactList",

            canClose: true

        }).then((pane) => {

            pane.navigate({

                pageType: "webresource",

                webresourceName: "apy_/webpages/sidepannel.html",

                data: encodeURIComponent(qs)

            });

        });

    }

    catch (e) {

        APY.Common.ShowAlertDialog("Ok", e.message + "An error occured. Please contact your System Administrator", "Error Dialog");

    }

};


  • Create A HTML Web Resource with below Code: 

<html>

<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">

    </script>

    <style>

        table {

            font-family: arial, sans-serif;

            border-collapse: collapse;

            width: 100%;

        }

        td, th {

            border: 1px solid #dddddd;

            text-align: left;

            padding: 8px;

        }

        tr:nth-child(even) {

            background-color: #dddddd;

        }

    </style>

    <script>

        var Xrm = null;

        function loadContacts() {

            debugger;

            Xrm = parent.Xrm;

            //get the current organization name

            var serverURL = Xrm.Page.context.getClientUrl();

            //var qs = decodeURIComponent(getParameterByName('data'));

            //var id = qs.substring(qs.indexOf("=") + 1);


            var id = Xrm.Page.data.entity.getId();

            var fetchXml = "<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false'>" +

                "  <entity name='contact'>" +

                "    <attribute name='fullname' />" +

                "    <attribute name='firstname' />" +

                "    <attribute name='lastname' />" +

                "    <order descending='false' attribute='fullname' />" +

                "    <filter type='and'>" +

                "      <condition value='" + id + "' attribute='parentcustomerid' uitype='account' uiname='Test' operator='eq' />" +

                "    </filter>" +

                "  </entity>" +

                "</fetch>";

            var encodedFetchXML = encodeURIComponent(fetchXml);

            var req = new XMLHttpRequest();

            req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts?fetchXml=" + encodedFetchXML, false);

            req.setRequestHeader("OData-MaxVersion", "4.0");

            req.setRequestHeader("OData-Version", "4.0");

            req.setRequestHeader("Accept", "application/json");

            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

            req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

            req.onreadystatechange = function () {

                if (this.readyState === 4) {

                    req.onreadystatechange = null;

                    if (this.status === 200) {

                        var results = JSON.parse(this.response).value;

                        debugger;

                        if (results.length > 0) {

                            for (let i = 0; i < results.length; i++) {

                                var html = "<tr><td><p onclick='productClicked(" + results[i].firstname + ");' style='cursor: pointer;text-decoration: underline;color: blue;'>" + results[i].lastname + "</p></td><td>" + results[i].fullname + "</td></tr>";


                                $("#contactsLists").append(html);

                            } 

                        } else {

                            Xrm.Utility.alertDialog(this.statusText);

                        }

                    }

                }

            };

            req.send();

        };

        function productClicked(ProductNumber) {

            console.log(ProductNumber);

        };

    </script>

    <meta charset="utf-8">

    <meta>

    <meta>

    <meta>

    <meta>

    <meta>

</head>

<body onload="loadContacts()" onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;">

    <table>

        <thead>

            <tr>

                <th>Contact</th>

                <th>Information</th>

            </tr>

            <tr>

            </tr>

        </thead>

        <tbody id="contactsLists">

        </tbody>

        <tbody>

        </tbody>

    </table>

</body>

</html>

  • We can show the Contact View by using Side Pane



Xrm.App.sidePanes.createPane({
    title: "Contacts View",
    imageSrc: "WebResources/sample_reservation_icon",
    paneId: "ContactList",
    canClose: true
}).then((pane) => {
    pane.navigate({
        pageType: "entitylist",
        entityName: "contact",
    })
});

  • We can show Contact record by Using Side Pane


var primaryContact =   formContext.getAttribute("primarycontactid").getValue();
//"d8393ace-8726-ec11-b6e6-000d3ac9b3f7",
Xrm.App.sidePanes.createPane({
    title: "Contact Record",
    imageSrc: "WebResources/Contast_Icon",
    hideHeader: true,
    canClose: true,
    width: 600
}).then((pane) => {
    pane.navigate({
        pageType: "entityrecord",
        entityName: "contact",
        entityId: primaryContact[0].id,
    })
});
  • We can show Dashboard in Side Pane:


Xrm.App.sidePanes.createPane({
    title: "Contact Record",
    imageSrc: "WebResources/Contast_Icon",
    hideHeader: true,
    canClose: true,
    width: 600
}).then((pane) => {
    pane.navigate({
       pageType: "dashboard",
   dashboardId: "2701de60-8f2a-48a4-8262-4a35ca7441fa"
    })
});

  • We can show the web resource Page with Side Pane



Xrm.Panel.loadPanel("https://org54c694bf.crm8.dynamics.com/main.aspx?etc=9333&pagetype=webresourceedit&appSolutionId=%7bC0F8C6B4-8526-EC11-B6E6-000D3AC9B3F7%7d&id=%7b7A38978D-8626-EC11-B6E6-000D3AC9B3F7%7d&_CreateFromType=7100&_CreateFromId=%7bC0F8C6B4-8526-EC11-B6E6-000D3AC9B3F7%7d#617662553", "Landing Page");

    }

  •     Based on our requirement we can show different pages in Side Pane.






 



Comments

Popular posts from this blog

Meta Data Using WebApiRequest

Sample CRUD Operations Using C# in MSCRM

Basic Plugin Code in D365 using C#