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 product and service pricing

This is the 3rd blog of this series, before this I have created a blog on the first topic “Perform initial configuration steps”  from Module 1 which you can check here : MB2-877 Microsoft Dynamics 365 for Field Service Module 1 Topic – Perform initial configuration steps

In this blog we will cover up the second Topic from the module 1 “Configure product and service pricing

NOTE : Before we start the module I would strongly suggest you to understand product catalogue in dynamics crm as we will be using price lists, products, unit groups etc alot :   https://docs.microsoft.com/en-us/dynamics365/customer-engagement/sales-enterprise/set-up-product-catalog-walkthrough   and if you have the knowledge already lets begin:

 

  1. Configure product and service pricing features including minimum charge amount, minimum charge duration, and the flat fee option
    You can add default “Standard” Price List to your Product in field service, however when you think about “Service” you might want to handle its price list slightly different. In Field service to accomplish this “Field Service Price List” has been added to dynamics CRM:
    Once you have configured a price list , you then navigate to “Related” option and click on “Field Service Price List Items”.

    ( Note that My field service is in Unified Interface so don’t get confused, I am intentionally using field service application – Once you have created a dynamics CRM trial for yourself which should include field service module too, you will see the field service app which you can access :

    So, Once your default price list – navigate to the related Field service price list and click on “Add new field service price list”

    If you see above I have set Flat Fee, Min Charge Amount & Minimum Charge Duration. Let’s understand what these options are:

    Flat Fee – If enabled then the pricing of this item will be not be multiplied by the quantity  and also Let’s you decide if a fixed fee for this service applies.

    Minimum Charge Duration–  If this field has a value , The Min charge will first apply to the minimum duration and beyond the min duration the standard charges will apply in short it will make some amount of time service free.

    Minimum Charge Amount –  As name suggest these are minimum charges for this service which correlates to the min charge duration. 

    lets do some math, assume my training per hour charge is 20,000 INR.
    now if  I apply above field service price list. The requirement is for 5 hours of training. then the math goes like this:

    Minimum Charge Duration defined by me is 1 hour. The requirement is 5 hour which means the bill will be for 4 hour which is 4*20,000= 80,000 INR then on this my minimum charge amount will be added which is 10,000 INR. So the final bill will be 90,000 INR.

     

  2. Add Products & Services to Incidents

    To this, simply navigate to Field service > Incident Type and add incident type. Once you do that; Now When you creating a work order and select incident there – it creates an incident for you which will have the product or service associated. so on a work order you can add product or services via incident.

  3. Determine when a Product has default Price List and a work order price list.

    Here are some quick points to cover up this topic. As we know Price List can be associated to following entities:

    • Account
    • Work Order
    • Agreement
    • product or service

    There there can be a clash in which price list to be used when they combine such as what if work order has a price list & also associated product has a price list too, in that scenario we’ll consider below:

    a. The Work Order Price List is used if a product has a different default price list than the Work Order

    b. The price of the product will come from the list price on the product if an Item is not on the Work Order Price List


  4. Associate Products & Services to Price Lists.

    Its Quiet easy and straight forward to associated a product or service to a price list. To do this go from Field service navigation > Field service navigation then click on an existing price list or create new as needed.



    Open an existing price list or create new one and click on “Price List Items” & click on “+Add New Price List Item”:



    Add the Product to it in my case I have added as “Exam preparation” and its Unit in “Hour” which is all defined on the product level and click on Save and Close.



  5. Define tax code.
    You can define tax code within your dynamics CRM field service. Remember you can have different scenarios/requirement to have different – different tax codes.

    To define a tax code, click on the dynamics 365 navigation from within field service app and click on field service setting and then on “Tax Codes“:

    Click on “Add new tax code”:

    Few important points on Tax Codes:  
    a. Used to define how tax on Work Order charged
    b. Tax options for products,
    agreements, and services
    c. Can be individually defined
    for each taxable item
    d. A tax code can contain
    multiple child tax codes and hence the total tax is defined by the sum of all the children.

 

MB2-877 Microsoft Dynamics 365 for Field Service Exam Overview

I have been planning for this certification since quiet a while now. I am very much attracted towards the field service addition to dynamics CRM hence I decided to finally schedule the exam.

So will be preparing for this exam for next couple of weeks & as I go, I will be creating blogs on my study for this exam. I will try to put as much as details and explanation to understand the concepts.

The blog series will be fully aligned with the exam pattern given on the Microsoft learning page:

1.png

Visit this page here :  https://www.microsoft.com/en-us/learning/exam-mb2-877.aspx & familiarize yourself with this exam.

What will you get out of this exam?

Well, I should have wrote this question in the beginning of this blog but it is not too late to talk about this now!
If you have a client which very much customer oriented and does a lot field work such as proving services as at home such as Instillation, uninstallation, fix/repair/service of the products that company offers,  The field service module of dynamics CRM is perfect for them. Hence you have to have knowledge on this module of dynamics CRM.

I am very much excited to start the series and hope so are you.
In the next and very first blog, We will go through the the first main topic “Perform Initial Configuration Steps”  from Set up and Configure Field service module.

2.png

So, I will see you in the next blog shortly! Make sure you subscribe to my blogs to get notified on next blogs!

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.