Tuesday, January 29, 2019

Refresh form after Dialog Process complete in MS CRM


How to refresh the form after Dialog Process complete in MS CRM?

The simple answer to this question is to have invoked a Dialog via Custom button and Jscript and do the refresh from within Jscript code. Here is a few line of code to achieve the same. 

Here I am using Alert.js v2.1 - Copyright Paul Nieuwelaar Magnetism 2016

function CallDialogProcess()
{   
    var recordId = Xrm.Page.data.entity.getId();
    var dialogId = "FD8B50BD-41A6-42D9-B00A-7BD9ED9BEBFB";
    var entityLogicalName = "contact"; 

    Alert.showDialogProcess(dialogId, entityLogicalName, recordId,
        function () { Xrm.Page.data.refresh();
    });
}

But now the challenge comes as when you might promote your code to Production or UAT environment. Putting Hard coded Guid will give you trouble at critical time, especially when going live with certain deadlines.

Now we need a simple Rest API query to get the relevant Dialog/Workflow Id, so we can pass it as a parameter.


Here in this post, I am suggesting a method which will help us achieve our goal without hardcoding dialog Guid.


function CallADialogProcess()

{
var dialogName = 'My Dialog Process Name';  // Provide Name of your Dialog Process here...

var selectClause = '$select=name,workflowid,_parentworkflowid_value,statecode';
var filterClause = "&$filter=statecode eq 1 and _parentworkflowid_value ne null and name eq '" + dialogName + "'";
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/workflows?" + selectClause + filterClause, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var results = JSON.parse(this.response);
            var i = 0;
            if ((i + 1) === results.value.length)
            {
                   
                var _parentworkflowid_value = results.value[i]["_parentworkflowid_value"];
                   

                var recordId = Xrm.Page.data.entity.getId();
                Alert.showDialogProcess(_parentworkflowid_value, "contact", recordId, function () {
                    Xrm.Page.data.refresh();
                });
            }
        }
        else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();
}

Please Note the highlighted code part, where we are actually fetching the Dialog Guid.

I love contributing what I am learning J

Regards,
Vipin Jaiswal
Vipinjaiswal12@gmail.com

Wednesday, January 23, 2019

Cannot insert duplicate key in MS CRM when importing a Solution


A record with these values already exists. A duplicate record cannot be created. Select one or more unique values and try again.

0x80040237  Cannot insert duplicate key.

I got this exception while importing a solution to my QA environment from DEV slot.

Initial Investigation

From the import log, we need to check the sequence whether the error occurred below the “Entity Ribbon” Item Type:


If this is the case, then the most likely cause is duplicate or corrupt CustomControlDefaultConfigs settings.

Solution

1) Identify which entity caused the failure. For example, from the screenshot above we can see the failure comes from the particular entity.

2) Open the solution customizations.xml file and find the problematic entity. Under that entity find the CustomControlDefaultConfigs node and extract the Guid(s) of the default CustomControlDefaultConfigId:



3) Now delete from the source environment this record. This cannot be done via UI unfortunately. So I am using my favorite XrmToolbox to verify and delete the record.


Here is fetchXML to be used 

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="customcontroldefaultconfig">
    <filter type="and">
      <condition attribute="customcontroldefaultconfigid"
                 operator="eq"
                value="{a88b6a06-3f20-e811-9661-00155d00a048}" />
    </filter>
  </entity>
</fetch>

Change the Guid in Fetch xml.

You can use FetchXML Tester to verify if the record exists and after delete again you can run to verify if record got deleted.



To Delete a record we would we would use Bulk Delete Tool






Once record is deleted, try import the same solution again and it should work.

Thanks.
Vipin Jaiswal


Thursday, January 10, 2019

"The unit id is missing" for Product in Dynamic CRM


I was doing data import for Product entity from one CRM Organization to another and facing a very common issue, but the solution is little bit different for it.

Before I start further on this thread, here are some tips for doing Data Migration in Dynamic CRM

If you wish to use CRM Configuration Migration, here are some tips to avoid any possible failure - https://vjcity.blogspot.com/2019/02/crm-configuration-migration-not.html

I started reading about this issue on internet and community blogs and everyone commented that Product might be missing below these two attributes

Display Name
Internal Schema Name
Unit Group
defaultuomscheduleid
Default Unit
defaultuomid


I double checked for all Products to verify where I missed providing these value, but guys wait these two attributes are mandatory by default in Dynamic CRM. Not a single product I have without these attributes populated.

What next - I was asking to myself

I observe that not all products are failing to be imported and I had a problem with only few. I was able to find that which all products are not getting imported by comparing what got imported and what not. This helps me narrow down my investigationJ.

I further observed that in Product configuration for the products which are failing to get imported are configured with Default unit whose base Unit is not set or you can say Product are configured without base unit.




Solution
For product data migration, I then took following approach
  • Created a Dummy Unit and set its Base Unit to the one who equivalent to the one.
  • Changed Default Unit of failed product to the Dummy Unit created here.
  • Change the Unit of PriceListItem to the Dummy Unit too.
  • Run the import and revert back the Dummy Unit to the original one.

Bonus Tips
  • Products that are retired, do not get linked to the PricelistItem and therefore import will failed to link up them during import.
  • Avoid Bulk update with all related entities and completely rely on migration tool or your code. Follow a sequence in Import especially in Product related import. Here is a sequence
  1. Unit Group
  2. Unit
  3. Product
  4. PriceListItem
  5. Account, Contact, Opportunity, Quote, Order and Invoice.
  • Provide name of the Product and Product ID to be unique to easily located in Lookup.

Regards,
Vipin Jaiswal
Vipinjaiswal12@gmail.com

Tuesday, January 1, 2019

Tips for troubleshooting in Microsoft Dynamic CRM


This card cannot be used – Nikon Camera External Memory Card Error.

I was getting a flash error message (This card cannot be used) on my Nikon Coolpix P510 for a external memory card.

The same external memory card was working perfectly fine on a laptop.

I tried few things like
  • Clean the card with soft cloth.
  • Turning camera On and Off for few times.
  • Format the card on a laptop, both quick and full format.

Unfortunately, none of these worked for me L

Then I thought card can't be corrupt, otherwise it will not be working on my laptop. I thought, there is something wrong with the camera settings.

But, I was not able to do any operation as my camera was stuck with an error message and not allowing me to do nothing.

Solution
  • I removed the external memory card.
  • I turn my camera On with only internal memory.
  • I then did a RESET camera to factory setting, and yes this solved my problem.


Conclusion

You might be thinking why I am writing about how I had fix my Camera problem. But let me tell you, that some time learning from small issue also a good experience to show case how to troubleshoot any exception or problem in Dynamic CRM too.

Whenever we get any unknown exception in Dynamic CRM, the very first thing we do is to google it down, to know the detail of underline exception.

We often ignore the process chain which might have caused an error to occur.

Here are some tips which really helped me when I am doing troubleshooting.

Don’t Assume
We waste many hours investigating problems and looking for solutions based on an incorrect assumption. When dealing with problems don’t assume anything, check assumptions and cross them off.  Lots of times you will find the problem.

Narrow down - Problem Domain
Googling, only base exception will give you thousands of articles and it might mislead you. First we need to narrow down and get it to the inner exception and google only about related inner exception, which could result in better articles explaining the possible cause and solution to the problem.

Understand Technical and Functional side of an error.
There could be a possible chance that some developer had thrown an exception in such a way that it looks like the system exception, but it might be valid exception. While troubleshooting, one needs to be fully aware of the functional process and he may have to guess but the guessing should be supported by process to narrow down the root cause of the error.


Regards,
Vipin Jaiswal