Task-10

User Story: -

Create an HTML page and show the account mark in red color font for city equal to dallas, show in left navigation form.


Detailed Explanation: -

We should create an HTML page and show it left navigation, in that HTML page we should show the list of accounts available in the CRM and accounts with dallas as city should be in red color font.

Sudo Code: -

  • Create an HTML page, and inside the <script> tags provide the JavaScript code.
  • In this JavaScript code, I should retrieve the list of account names with city names in the CRM by using Xrm.WebApi.online.retrieveMultipleRecords method, we need to provide "parent" in front of this method to access it from the parent HTML page context.
  • You can get this code by using REST builder.
  • Using for loop for each record, you should create an HTML paragraph element with textContent as the name of the account record.
  • Now check the condition if the city name equals Dallas check for lower and upper cases using ToLower().
  • If the condition is satisfied then set the HTML color to red.
  • Append the element to the main div element.
  • Now create an HTML web resource with the HTML code we wrote.
  • Open CRM advanced settings => Customization => Customize the system => Client Extension.
  • Here you can select the required Model Driven App or you can select the Site Map to add to Custom-D365 
  • Here you can Add your web resource by selecting the Type as Web Resource.



HTML Code: -

<html>


<head>
    // we can write the JS function within script tags and call it
</head>

<body>  
    <div id="ListOfRecords"></div>
    <script>
        let ListOfRecords = document.getElementById("ListOfRecords");

        // "parent" is used to call previous context methods or variables...etc
        // because Xrm in not defined in this new HTML page.
        parent.Xrm.WebApi.online.retrieveMultipleRecords("account", "?$select=address1_city,name").then(
            function success(results) {

                for (var i = 0; i < results.entities.length; i++) {
                    var address1_city = results.entities[i]["address1_city"];
                    var name = results.entities[i]["name"];
                    let id = "element" + i;

                    // Creating Paragraph element
                    let list_Item = document.createElement("p");
                    list_Item.id = id;

                    list_Item.textContent = name;
                    if (address1_city != null) {
                        if (address1_city.toLowerCase() == "dallas") {
                            list_Item.style.color = "red";
                        }

                    }
                    ListOfRecords.appendChild(list_Item);


                }
            },
            function (error) {
                parent.Xrm.Utility.alertDialog(error.message);
            }
        );

    </script>

</body>

</html>








Results: -



Comments

Popular posts from this blog

How to create an Azure AD(Active Directory) and create an application to connect Dynamics 365 from console application

Task -6 JavaScript , Regular expressions

Task_1 JavaScript