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

As we’ve seen in the previous articles on How to work with Power BI in Dynamics 365 for Sales and Service as well as How to work with Power BI in Dynamics 365 for Sales and Service–Part 2, we can leverage the existing content packs to simplify our data presentation for the Sales and Service modules in Dynamics 365. And that works fine if your requirements conform to what’s already built in those content packs. But most of the time that’s not necessarily the case.

Let’s have a look at how you can work with Dynamics 365 Customer Engagement data in Power BI from scratch. We’re going to be doing this from Power BI desktop. If you don’t have it installed on your machine, grab it from the Microsoft Store or from here.
Read the rest of this entry »

Advertisements

In some instances, you might need to put a lookup on a form, and based on the selection in that lookup, retrieve additional data about the entity referenced. One such example could be either the standard entities like Account or Contact, or a custom entity you have created.

The following snippet will help you do that, but first, be aware of a few things:

1. Using OData, you can make calls back to the server, and get the values you need. Whether calling your custom entity, or the default ootb ones, the easiest way to determine what you are calling is to have a look at the XML returned by a call to the web service:

http://[servername]/[orgname]/XRMService/2011/OrganizationData.svc

the return XML will give you all the available entity names. Find the one you need in there, as you will be using it in the script.

2. Use the following script on lookup change event:

        try
        {
            //Get entity data;
            var serverUrl = Xrm.Page.context.getServerUrl();

            var odataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/new_specialtiesSet(guid’" + guid + "’)";
            // alert("ODATA Select: " + odataSelect.toString());
           
            $.ajax({
                type: "GET",
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: odataSelect,
                beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
                success: function (data, textStatus, XmlHttpRequest) {
                    var org = data.d;
                    //Change form data
                    Xrm.Page.data.entity.attributes.get("new_specialtydescription").setValue(org.new_Description);
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert(‘OData Select Failed: ‘ + odataSelect);
                }
            }
            );
           
        }
        catch(err)
        {
            // handle the error

        }

3. Observe two highlighted sections:

new_specialtiesSet is the value obtained from the XML returned by the web service call. To this value we pass the GUID of the current entity, which we can get by using this script:

var lookupItem = new Array();
lookupItem = Xrm.Page.getAttribute("new_specialty").getValue();

if(lookupItem[0] != null)
{
    var name = lookupItem[0].name;
    var guid = lookupItem[0].id;
    var entType = lookupItem[0].entityType;
}

org.new_Description is the actual field name in the looked-up entity (new_Description).

This way you can start populating current form fields with values from the look-up entity selected by the user. Be aware though that there might be a delay from look-up value change until the call takes place, results are returned and fields are populated. Depending on the environment, this could be visible or instant.

Enjoy!

Microsoft Business Solutions MVP

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 507 other followers

Follow Dynamics 365 Wizardry on WordPress.com