Improve fetch xml performance by using latematerialize option.

If you have been working on dynamics projects, I bet fetch xml is your best friend as it’s really an easiest way to query and execute in order to get required results. Along with that, constructing it in advanced find is super easy too.

Don’t forget about amazing XRM toolboxes which helps you creating even complex fetch xml queries.

It all sounds fun and easy till your fetch XML becomes really heavy with so many joins or you have a requirement where you need to make many joins.

A Quick tip!

You can have a maximum of 10 joins in fetch xml for dynamics CE.

You will notice that retrieval from dynamics is getting slower and slower as fetch xml becomes complicated. I have faced something similar multiple times. What I did?

well, there are multiple options one of which I want to cover today as using this option, there are no extra efforts.

latematerialize to the rescue!

All you got to do is add latematerialize=”true” in fetch xml properties like below and test is to see the magic.

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" latematerialize="true">
  <entity name="account">
    <attribute name="emailaddress1" />
    <attribute name="statecode" />
    <attribute name="statuscode" />
    <attribute name="ownerid" />
    <attribute name="accountnumber" />
    <link-entity name="contact" from="contactid" to="primarycontactid">
      <attribute name="birthdate" />
      <attribute name="createdon" />
      <attribute name="contactid" />
      <attribute name="parentcustomerid" />
    </link-entity>
  </entity>
</fetch>

There are many internal technicalities as to how it works but to summarize, It breaks the data into multiple smaller segments which makes the retrieval of data faster unlike normal fetch xml which tries to query every at once.

if you are looking for official documentation on the same, please go here: Improve FetchXML request performance – Power Apps | Microsoft Docs

Advertisement

No “Change Tracking” option available under entity definition?

No change tracking available under entity definition.

To be able to add an entity to data export service, you would need to make sure the change tracking option is enabled on the entity definition.

we generally go to Settings – > solution or customize the system -> look for the entity and under “Data services” option, you should see the change tracking option. However it’s not the case anymore.


The option has disappeared from classic UI entity definition.

So where is this setting now? Well, you will find it in https://make.powerapps.com portal now. In order to see it, go to powerapps portal or click on above url.


1. Make sure you in the right environment from top right corner.
2. Click on solutions from the left menu:

3. Select the solution in which entity is there or default solution.
4. Navigate to the tables and click on the desired table and click on edit.


5. Again click on “edit table properties”

6. Expand advanced option section and select the “Track Changes” Option:

And that it! you should be good to go after publishing.

MB2-877 Microsoft Dynamics 365 for Field Service Module 1 Topic – Configure bookable resources

This is the 4th blog of this series, before this I have created a blog on the topic “configure products and services pricing”  from Module 1 which you can check here : MB2-877 MICROSOFT DYNAMICS 365 FOR FIELDSERVICE MODULE 1 TOPIC – CONFIGURE PRODUCT AND SERVICE PRICING In this blog we will cover up the topic from the module 1 “Configure bookable resources
  1. Identify Fields for bookable resources Let’s understand what is a bookable resource, well, a bookable resource in Field Service is anything that you’re going to need to carry out a work order.  Now, it could be a user, so an employee of your organization that is actually going to go out in the field and work through something. And it doesn’t necessarily have be a person it could be anything in field service. To create a bookable resource ,from your field service >click on “Resource Scheduling” and then on “Resources”:
  2. below the are main fields that needs defining when creating a bookable resource:       Resource Type – Can be of type User or Contact or Account etc. Skills & Certifications – Resource Skills and achievements Roles & Categories –  Resource’s Roles Working Schedule – Resource’s work routine i,e start & end time. Hourly Rate – Resource’s Charges.   Location Information –  Work start and end location.   Schedule Board Display Options –  Yes/No Territory Information –  Territory a resource belongs to.
  3. you will have to complete all this information here on the different tabs available below such as “project service”, “field service” & Scheduling:
  4. Enable mapping functionality You can enable mapping functionality which is a concept of geo location, making sure that, when a work order is created, that we understand the exact physical location of where that work order is to be executed from a service technician perspective. By default this is Disabled in field service + Project Automation.
  5. To Enable go to from Field Service > Resource Scheduling > Administration and click on Scheduling Parameters:
  6. Change “Connect to Maps” field to “Yes”. Once you do that you will be presented with a warning popup. Click okay and the mapping functionality will be enabled.
  7. Identify entities that are geocoded Out of the box, accounts and work orders are all geo located to ensure that they are physically tied to an actual, mappable address that can be used through like Bing Maps or Google Maps or something similar to that functionality.
  8. To see this open an account and from ribbon navigation click on “Geo Code“:
  9. It will then actually try to map the address given on this account to an actual physical address on the map and give you suggestion. select and click okay and save the account.
  10. Define start and end location for resources  & Identify differences between address types A resources might physically start their day at the office.  So it might be a situation where the technician’s going to come into your office.  Once they come into your office, they’re going to get the all the accessories they need for that particular day, their stack of work orders, and then they’re going to head off into the office.  So with the option of start and end location you will be able to map your routing information based upon where they start their day.  So if they start their day at the office, you know that that’s how you want to work through it.  The other option could be that they’re starting their day from their physical resource address.
  11. To define this – follow step  1 given above for creating a bookable resource and go to “Scheduling” tab:
  12. you get couple of option which means as below:
  13.  a. Resource start and end locations are used to help plot a                             resource’s daily route
  14.    b. Start and end locations can be defined as:
    •  Location Agnostic: Does not have a defined address
    • Resource Address: Uses the address defined for the resource
    • Organizational Unit Address: Uses the address defined on the resources organizational unit
  15.   c. Address play a direct role in whether a resource is suggested for           a Work Order in the Schedule Assistant
  16. So, this is it – i will see you in the next blog.

MB2-877 Microsoft Dynamics 365 for Field Service Module 1 Topic – Perform initial configuration steps

Before this blog – I have provided an overview about this exam which you can see here: MB2-877 Microsoft Dynamics 365 for Field Service Exam Overview

In this blog we will be focusing on the module 1 “Set up and configure Field Service” and first  topic “Perform initial configuration steps”:

2

  1. Identify key security roles.

    A user in Field Service is a member of your organization who will use a Field Service license. Security roles define which entities a user can view as well as how they can interact with those entities. Field security profiles define which fields a user can see. As an example, a user may have permission to see accounts but not to see specific fields for an account. Field Service comes with four predefined security roles and field security profiles:

    • Field Service Administrator: Generally assigned to key people within the organization who need access to the Administration tile. Global access to all Field Service entities.
    • Field Service Dispatcher: Generally people in the organization who are responsible for scheduling and need to manage resources and work orders.
    • Field Service Resource: Generally people within the organization who will access Field Service from a mobile device.
    • Field Service Inventory Purchase: Generally people within the organization who are responsible for inventory, purchase orders, RMAs, and RTVs.
    • Field Service App Access: these would be the people who really only need to have access to the Field Service mobile application.  So they don’t necessarily need the full gamut of functionality from a resource standpoint, but they do need to be able to login to the application, see what work orders have been assigned to them, and carry out some basic day-to-day functionality.
  2. Identify resource scheduling options.

    Resource Scheduling is all about understanding who and what resources you have available to be able to work through these different projects or service tickets that need to be done.  So as part of the resource scheduling scenario, this gives you kind of a one-stop shop or a single point of contact to be able to go out and manage some of the different shared scheduling components in the application.

    This can be divided into 3 categories:

    In short to understand this, You define resources , resource roles & skills etc and then you can schedule work orders using the Schedule Board. Also you have some Settings that you can do for example setting up Orgnizational Units i,e you may have services that you provide over different countries so you can create different organizational units such as one for India, One for UK etc.

  3. Identify entities that can be customized with administrative settings.

    This allows an administrator to customise entities as per business field service requirement. Below entities can be included in this process :

    • Characteristics
    • Territories
    • Priorities
    • Warehouses
    • Postal Codes
    • Products
    • Bookable Resources
    • Price Lists
    • Time Groups
    • Payment Terms
    • Incident Types
    • Tax Codes
    • Booking Statuses
    • Service Task Types
    • Booking Rules
  4. Identify Product & Services Categories. Before Understand the Product Categories, lets understand what is a Product and a Service.
    • Products are anything the company sells
    • Services are products that are designated as a service the company provides
    • Can be added manually to a Work Order when created
    • Can be added automatically to a Work Order from an associated Incident Type
    • May be marked as “used” billed to a client or left as “estimated” on a Work OrderField Service related products can be defined as any of the following:
      • Inventory: Products sold and deducted from inventory
      • Non-Inventory: Products sold but not tracked in inventory
      • Services: Sold on time and materials basis & Price and costs are hourly rates

                      Duration of Service:

      • Manually Entered on mobile by field agent
      • Derived from elapsed time between work order schedule statuses


      In the next blog, we will go through the topic 2 from module 1 – Configure product and service pricing

Handle Boolean/Two Option Fields In Scribe Data Migration/Bulk Update

I know many CRM developer get into Data migration or bulk update operation from CRM system to other external/CRM system.

I have gathered few useful tips while dealing with boolean fields as in how to check the value , reverse the value , use nested if with OR & AND conditions etc. I have categorised them into below and provided explanation & solution.

  1. Check Values from Source & Set New Value 

    To check value of a boolean field from source do this and set other value:

    IF(S1=1, 0 , 1)

    (Here i am checking if S1 field value is “1” which is “TRUE” then set the new value to “0” which is “FALSE” otherwise the default will be to “1”.)

  2. Check Combination of boolean fields and Set New Value

    To check the combination of values i.e If a=1, b=0 then set some new value, Do this:

    IF(AND(S1=1, S2=1), 0 , IF(AND(S1=0, S2=0),1 ))

    (here i am checking if S1=1 AND S2=1 then outcome should be “0”.
    please note: you can use “OR” operator as well as per your requirement.)

  3. Check If the value is Null or Any error in retrieving the value and set default value

    You might have to handle null values in the package, to do this:

    IF(ISERROR(S1),TRUE(), FALSE())

    (here I am checking if S1 is null or any error then i am setting the value to TRUE otherwise FALSE.)

    you can also combine this with checking other values to such as if S1 =1 then 1 , S2=0 then 0 & if S2=Null then TRUE().

    IF(ISERROR(S1),TRUE(),IF(OR(S1 =1 ), 0,IF(OR(S1=0),1)))



    I hope this helps! I will try post help blog on other types of fields.
    cheers!

Plugin Image Not Transferred with plugin Step In Deployment

Quick Blog:

I have recently encountered this issue where in a plugin image was not transferred along with the plugin step in the deployment.

Cause:

The plugin step was profiled in the source environment and the solution containing it was exported and deployed to other org.

I have a feeling if your plugin is profiled, the image will not be taken to other environment. Obviously it was a miss from the developer but this is something new i saw.

Solution:

All i did was unregistered the assembly from target environment —> unprofiled the step in source system — >exported the solution again from source — ->deployed the solution to target.

 

Hope this helps!

 

Get Most Recent Created On Record from Retrieved Entity Collection In Plugin

Sometimes, you may have a requirement to get the most recently created on record from the entity collection you have retrieved.

Instead of playing around a lot with coding and .net stuff, Dynamics CRM fetch XML and QueryExpression provides a way to sort records Ascending or descending.

Therefore, While retrieving records in FetchXML, do this :

<entity name='entityname'>
 <attribute name='atrributename1' /> 
   <attribute name='atrributename2' />    
    <attribute name ='attributename3' />                       
      <order attribute='createdon' descending='true' /> 
     <filter type='and'>                                  
     <condition attribute='statecode' operator='eq' value='0' />
   </filter>
</entity>

Or in Query Expression:

QueryExpression qe = new QueryExpression(entityName);
FilterExpression fe = new FilterExpression();
qe.ColumnSet = new ColumnSet(true);
qe.Orders.Add(new OrderExpression(columnname, ordertype)); 
service.RetrieveMulti ple(qe);

 

when Execute them , you will get the desired record on the top which can be access by simply by doing retrievedResult[0] or :

firstRecord= retrievedResult.Entities.First(); //first method.

firstrecord

I hope this helps!

cheers!

 

Retrieve Audit History Changes For A Particular Field/Attribute Of A Record

Description:

Sometimes we have a requirement to retrieve audit history changes for a particular field in CRM which may be for the purpose of checking if for e.g field A value which is at the moment set to “10”, was ever “5” or may be “3” or may be use old those values of fields to create a new CRM Record. In the below Image , you can easily retrieve old and new values at any given time on birthday field by looping on each audit record:

audit1

I have taken the reference from Dynamics CRM SDK & MSDN to figure out how this can be achieved.

Please note : To be able to use this you must have Auditing enabled on all three areas of CRM.

1. Auditing for whole Organization should be already turned on.

2. Auditing for Entity Should be already turned on.

3. Auditing for that Field should already be turned on.

Solution Code:

I have accomplished this on a console application , you can do it in plugins or custom workflows as per the requirement.

Required :

Namespace:   Microsoft.Crm.Sdk.Messages

Assembly:  Microsoft.Crm.Sdk.Proxy (in Microsoft.Crm.Sdk.Proxy.dll)

try
   {
//initiate a new retrieve request & add entity logical name + Guid of the record to retrieve
    RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest();
    changeRequest.Target = new EntityReference("contact", Id);                RetrieveRecordChangeHistoryResponse changeResponse =

//Execute the request, the "details" variable will have the audit data. 
    (RetrieveRecordChangeHistoryResponse)_service.Execute(changeRequest);
    AuditDetailCollection details = changeResponse.AuditDetailCollection;

// Retrieve Particular attribute change history by passing entity logical
//name and guid of the record, finally execute using RetrieveRecordChangeHistoryResponse
    var attributeChangeHistoryRequest = new RetrieveAttributeChangeHistoryRequest
      {
           Target = new EntityReference("contact", Id),
           AttributeLogicalName = "birthday"

       };

     var attributeChangeHistoryResponse = (RetrieveAttributeChangeHistoryResponse)_service.Execute(attributeChangeHistoryRequest);
     details = attributeChangeHistoryResponse.AuditDetailCollection;

//Details will have many records for example birthday change records, loop through all of them
       foreach (var detail in details.AuditDetails)
         {
             var detailType = detail.GetType();
             if (detailType == typeof(AttributeAuditDetail))
                  {
// retrieve old & new value of each action of each audit change from AttributeAuditDetail
                var attributeDetail = (AttributeAuditDetail)detail;
                foreach (KeyValuePair<string, object> attribute in attributeDetail.NewValue.Attributes)

                        {

                        string oldValue = "(no value)", newValue = "(no value)";
                        if (attributeDetail.OldValue.Contains(attribute.Key))

                       oldValue = attributeDetail.OldValue[attribute.Key].ToString();
                       newValue = attributeDetail.NewValue[attribute.Key].ToString();

                       if (oldValue !=null & newValue!=null)
                            {
                             // Do Something here!
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
}

I hope this helps!

How to use Configuration Migration / Data Migration Utility in Dynamics CRM

Explore Dynamics CRM

In this blog i will detail on using Configuration Migration/ Data Migration utility. This can be used to move the configuration data from one CRM environment to other. generally Configuration data is used to defines custom functionality in CRM, which is typically stored in custom entities.

Often we need to migrate configuration data from one CRM environment to other, especially test data, master data setup etc. Microsoft provided an excellent tool for doing this.

Following are the benefits of using this tool,

  1. allows you to select entity and fields from where you want to export the configuration data.
  2. large amount of data from multiple entities can be moved from one crm environment to other.
  3. Data can be imported using the same GUID’s as that of the source system, hence lookup references to imported records will be valid.
  4. Schema file can be reused to export data from different source environments.

Below…

View original post 718 more words

Solution Import Error 0x80044150 – Object reference not set to an instance of an object.

Issue:

While importing a solution I got a generic SQL error but when i downloaded the log file i saw below error:

import error1

0x80044150 – Object reference not set to an instance of an object 

I have seen this error in plugins several times but never in import but root cause and underlying issue remains the same.

The import was trying to find something which was not there in target.

Solution

There was a relationship in my solution exist as N:1 to an entity which was deleted from target system way back hence this error occurred. Using the relationship given in solution, CRM was trying to find related entity which wasn’t there.

 

Hope this helps.