You are currently browsing the tag archive for the ‘HTML’ tag.

Welcome back. This is a follow-up to a previously posted article which was showing how to get to some basic data from the entity hosting our web resource. The article is HERE.

In this part we take a step further. We have the web resource loaded on the Account entity, and we need to get to the related Cases. For this post, we’re only going to be looking at getting a count of related Cases, as well as some basic data.

For the sake of simplicity, we’re going to include JavaScript and CSS in the HTML resource. You should always separate the resources though.

Let’s start with a simple HTML page structure:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Context Info</title>
        <style type="text/css">
            body {
                background-color: #FFFFFF;
            }

        </style>

    </head>
    <body onload="OnLoad()">

    </body>
</html>

As you can see, in the onload of the body we’re calling a function called OnLoad(). Now let’s look at this function, and see what it does.

Right after we’re closing the style tag, add a new script tag. This will hold our function.

</style>

<script type="text/javascript">

</script>

Now let’s dig into our function:

function OnLoad() {

}

First off, let’s get the service URL built:

var _serverURL = window.parent.Xrm.Page.context.getServerUrl() +
    "/xrmservices/2011/organizationdata.svc";

Next, let’s build the XMLHttpRequest:

var AddressReq = new XMLHttpRequest();
                AddressReq.open("GET", _serverURL + "/IncidentSet?$filter=CustomerId/Id eq (guid’" + window.parent.Xrm.Page.data.entity.getId() + "’)", false);
                AddressReq.setRequestHeader("Accept", "application/json");
                AddressReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                AddressReq.send();

Pay attention to the fact that we’re looking for IncidentSet to retrieve Cases, and we’re filtering by CustomerId/Id to be the same as the current Account record.

Once we get the response, let’s process the response. We’re only going to output a very simple response in out HTML web resource. Later we can start looking at using this data for something more advanced.

if (AddressReq.readyState == 4 /* complete */) {
    if (AddressReq.status == 200) {
        var retrieved = this.JSON.parse(AddressReq.responseText).d;
        var Results = retrieved.results;
        document.write("There is a total of " + Results.length + " Cases associated:" + "<br />");
        for (var i = 0; i < Results.length; i++) {
            document.write(Results[i].TicketNumber + " : " + Results[i].Title + " : " +
                Results[i].IncidentId + " : " + Results[i].Description + " : " +
                Results[i].StateCode.Value + " : " + Results[i].StatusCode.Value + "<br />");
        }
    }
}

Now put it all together, and your final result on the page should be similar to this:

image

So now I see my two related Cases listed on the Account form, along with some details.

Next time we’ll look at using this data in a more meaningful manner.

Enjoy!

Advertisements

This post is just an introduction to a set of posts detailing how we can start taking advantage of HTML5 and some open source JavaScript libraries and frameworks within Dynamics CRM.

In this first post, we’ll be looking at getting to the most basic information from within a HTML Web Resource. Of course, knowledge of JavaScript and some basic CSS is required :)

For the sake of this example, and to keep things simple and easy to read, the script and the CSS are all built in the same file. Normally you would create a structure of 3 separate files, a HTML file, a JavaScript file and CSS file.

Start by creating a new HTML web resource. Place it in a iFrame on the Account entity.

The following code is commented to be self-explanatory, and is only meant to serve as a reference. Some of these calls will be used in future articles when we start looking at providing some real functionality on our records.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>Context Info</title>
        <style type="text/css">
            body {
                background-color: #b0c4de;
            }

        </style>
    </head>
    <body>
        <script type="text/javascript">
            // debugger;
            var xrm = window.parent.Xrm;

            // Display the client information
            // Web for Browser
            // Outlook for Outlook
            // Mobile for Mobile
            var _client = xrm.Page.context.client.getClient();
            document.write("Client: " + _client + "<br />");

            // Get the client’s URL
             var _clientURL = xrm.Page.context.getClientUrl();
             document.write("Client URL: " + _clientURL + "<br />");

            // Get the current theme
            // for Outlook
            // returns the following values:
            // Default for Web
            // Office12Blue for Microsoft Dynamics CRM for Outlook 2007 or 2010 Blue Theme
            // Office14Silver for Microsoft Dynamics CRM for Outlook 2007 or 2010 Silver or Black Theme
            var _clientTheme = xrm.Page.context.getCurrentTheme();
            document.write("Client Theme: " + _clientTheme + "<br />");

            // Get the base language
            var _baseLanguage = xrm.Page.context.getOrgLcid();
            document.write("Base Language: " + _baseLanguage + "<br />");

            // Get the Organization Unique Name
            var _orgUniqueName = xrm.Page.context.getOrgUniqueName();
            document.write("Organization Unique Name: " + _orgUniqueName + "<br />");

            // Get the current User ID
            var _userID = xrm.Page.context.getUserId();
            document.write("User ID: " + _userID + "<br />");

            // Get the User Language
            var _userLanguage = xrm.Page.context.getUserLcid();
            document.write("User Language: " + _userLanguage + "<br />");

            // Get the User Name
            var _userName = xrm.Page.context.getUserName();
            document.write("User Name: " + _userName + "<br />");

            // Get the User Roles IDs
            var _userRoles = xrm.Page.context.getUserRoles();
            document.write("User Roles: ");
            for (var i = 0; i < _userRoles.length; i++) {
                document.write(_userRoles[i].toString() + ", ");
            }
            document.write("<br />");

            document.write("Window size: " + this.innerWidth + ", " + this.innerHeight + "<br />");

            document.write("Working with record data: " + "<br />");

            // debugger;

            // Get a reference to the entity
            var _entity = xrm.Page.data.entity;

            // Get the entity name
            var _entityName = _entity.getEntityName();
            document.write("Entity Name: " + _entityName + "<br />");

            // Get the entity ID
            var _entityID = _entity.getId();
            document.write("Entity ID: " + _entityID + "<br />");

        </script>
    </body>
</html>

The output when opening a new Account form should be as follows:

image

On an existing record you will also get the Entity ID.

Now with all this information, we can start building something more interesting. Future posts will go into retrieving related data, and building some other functionality with it. So, stay tuned :)

Enjoy!

Microsoft Business Solutions MVP

Check out my course [Video]

Configuring and Extending Dynamics 365 Customer Engagement

Configuring and Extending Dynamics 365 Customer Engagement

Check out my course [Video]

Getting Started with Dynamics 365 Customer Engagement

Reviewed Book

Implementing Microsoft Dynamics 365 for Finance and Operations

Implementing Microsoft Dynamics 365 for Finance and Operations

Reviewed Book

Microsoft Dynamics 365 Extensions Cookbook

Microsoft Dynamics 365 Extensions Cookbook

Check out my Book

Microsoft Dynamics CRM 2016 Customization - Second Edition

Microsoft Dynamics CRM 2016 Customization - Second Edition

Check out my Book

Microsoft Dynamics CRM Customization Essentials

Microsoft Dynamics CRM Customization Essentials

Check out my Book

Microsoft Dynamics CRM 2011 Scripting Cookbook

Microsoft Dynamics CRM 2011 Scripting Cookbook

Reviewed Book

Microsoft Dynamics CRM 2011: Dashboards Cookbook

Microsoft Dynamics CRM 2011: Dashboards Cookbook

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 599 other followers

Follow Dynamics 365 Wizardry on WordPress.com