Wednesday, May 1, 2019

Deactivated business rule Running in MS CRM


Problem Statement

I have designed a plugin which is supposed to do some calculation and update some fields accordingly. But I realize that fields were not getting updated with correct values. I started debugging my plugin and I observe that plugin is doing the correct calculations, but fields are getting updated with some other values.

There were
  • No other Plugins registered who would affect
  • No other Workflows which might cause this odd behavior
  • Business rules does exist but were in De-Activated state.

I observed that though Business Rules were in deactivated state, but the formulas defined within them are giving an exact result which my fields are showing.

Now the question is Business Rule under Default customization are in Deactivated state but they still running in background affecting my plugin calculation and overwriting values in the field.

How can I check which business rule are still running?




Solution
The most powerful and favorite tool for any Dynamic CRM lover – Advanced Find. I have put a simple query to find all processes


I can see that there where multiple business rule with same name but may be different version (due to solution installation) and few among them were Activate state, which appears to be deactivated under default customization.



We need to deactivate or delete the respective business rule which might be causing a problem in dynamic CRM operations.

I hope this could save a lot of time.

Regards,
Vipin Jaiswal


Tuesday, April 16, 2019

Couldn’t complete execution of the plug-in within the 2-minute limit


Exception :
Unhandled exception:
Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute):  Plugins.InvoiceRowDiscountPostUpdate: System.TimeoutException: Couldn’t complete execution of the Plugins.InvoiceRowDiscountPostUpdate plug-in within the 2-minute limit.Detail:
  11660026-7fc6-4ee7-b43b-298d416013b9
  -2147220956
 
Business Requirement

When a discount of parent record gets updated, its need to
  1. Recalculate various tax amount and to update all associated child records.
  2. Update parent records itself with sum of calculated amount.



Root Cause Identified

We have Dynamics CRM Online SYNCHRONOUS plugin that was going on an infinite recursion when updating itself.

Solution
  1. We should remove all the attributes that are consider as filtering attribute in triggering the plugin from the entity before we trigger orgproxy.update

In my case, I had an attribute – new_discount

// Remove the discount attribute from the Parent Invoice Row to stop going in the infinite loop.
if (parentInvoiceRow.Contains("new_discount"))
   parentInvoiceRow.Attributes.Remove("new_discount");

    2) The update cannot be a part of ExecuteMultiple, even if you remove the triggering attribute. Below is self explanatory code 

UpdateRequest createRequest = new UpdateRequest { Target = singleChildInvoicerow };
requestWithResults.Requests.Add(createRequest);

// Cannot be a part of Request Multiple - going on an infinite Loop.
// UpdateRequest parentCreateRequest = new UpdateRequest { Target = parentInvoiceRow };
// requestWithResults.Requests.Add(parentCreateRequest);

// Execute all the requests in the request collection using a single web method call - for only Child Record.
ExecuteMultipleResponse responseWithResults = (ExecuteMultipleResponse)neoService.Execute(requestWithResults);

// Do a separate update for the parent record.
neoService.Update(parentInvoiceRow);

Plugin Registration Tool - Object reference not set to an instance of an object


Exception Details
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Xrm.Tooling.CrmConnectControl.CrmConnectionManager.SetConfigKeyInformation(Dictionary`2 configKeys)
   at Microsoft.Xrm.Tooling.CrmConnectControl.CrmServerLoginControl.StartConnectCheck()
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)


Steps by Step Approach to get Plugin Registration working.

Step 1) Download the latest SKD (https://xrm.tools/SDK), before you try other method to get things correct for you.

Step 2) Try Clean the content of the folder - C:\Users\Username\AppData\Roaming\Microsoft\PluginRegistration


The Folder contains Previous connections made.

Step 3) Clean any content from the folder - C:\Users\Vipin\LiveDeviceID



After cleaning the content of the folder, I was not getting any exception but then Plugin Registration Tool repeatedly asking me to choose the organization and I was got stuck in a loop.

So, I decided to have the latest SDK from - https://xrm.tools/SDK and then everything started working well. Its weird though, Tool should have complain about the version problem at the very first stage.


Here are some other links for Troubleshooting and learning:

·       Plugin in Dynamic 365 CRM

·       Connect to Dynamic 365 CRM from Console App using Azure Authentication

·       Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

·       Unable to Login to Dynamics CRMOrganizationWebProxyClient is null

·       Assembly 'Microsoft.Crm.Sdk.Proxy' with identity 'Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'Microsoft.Xrm.Sdk' with identity 'Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

·       Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.

·       Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

Wednesday, March 20, 2019

An existing connection was forcibly closed by the remote host



The most likely cause for this is you might be using the old Report Authoring Extension which is not compatible for latest support for TLS 1.2 protocols that have been implemented with latest CRM SDK.
You can update Report Authoring Extension with latest one from here

If you might encounter such kind of error when programming then try to go through below blog - https://vjcity.blogspot.com/2018/04/microsoft-dynamic-crm-v90-and-tls-and.html



Hope this Help!

Thanks.
Vipin Jaiswal
vipinjaiswal12@gmail.com

Showing external website in IFrame in Dynamics 365.


Probably the most common page for a developer is www.google.com

I was trying IFrame component in dynamic 365 CRM and Google being my favorite, I tried to render Google.com to an Iframe within Microsoft Dynamic CRM.

I was unable to render Google.com to an Iframe within Dynamic 365 CRM.

This is NOT at all a dynamic 365 CRM problem, we cannot (in a simple way) render Google page within an IFrame. You can try in W3Schools.com too.


Reason:

Google sends a "X-Frame-Options: SAMEORIGIN" response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page.



Note: 
Try loading some other website in an IFrame within Dynamic CRM and it should work like a charm.

Some common blogs or something – I used my own blog - https://vjcity.blogspot.com/

Modifying URL of IFrame by passing parameter using JavaScript.


A URL is mandatory attribute when inserting an IFrame on a form. Let’s populate it with URL with only base address of our desired website and passing the required parameter from JavaScript.


JavaScript Code to pass a record id (Guid) to an IFrame URL.

Call this function on the load of the form.

function passIdtoIframe()
{
    var recordId = Xrm.Page.data.entity.getId();
    recordId = id.replace("{", "").replace("}", "")

    var IFrame = Xrm.Page.ui.controls.get("IFRAME_Contact_view");

    var UrlwithIdAppended = IFrame.getSrc() + recordId;

    IFrame.setSrc(UrlwithIdAppended);
}


Breaking an Ice: What if, I really need to display google search result within Dynamic CRM by passing some parameter? Can we achieve this or not?

I will update blog with some more findings. 

Hope this help!

Thanks.
Vipin Jaiswal
vipinjaiswal12@gmail.com

Tuesday, March 19, 2019

How to calculate Age in Dynamic 365 CRM




One of the most common requirements in Dynamic CRM is to view the age of the customer/contact or individuals. It seems to be pretty straight forward but it is a bit challenging.

First, I tried calculating Age from Business User favorites which is – Business Rules in Dynamic CRM.





Business Rule was giving me a hard time and then I moved myself to the Developers favorites – JavaScript.

Below JavaScript code is pretty straight forward and we just need to register event on change of a Birthdate of any other date field. I created a new firld new_age of type Whole Number.


function onChange_birthdate()
{
    var birthday = Xrm.Page.getAttribute("birthdate").getValue();
    if (birthday != null)
    {
        var age = calculate_age(birthday.getMonth(), birthday.getDate(),                                  birthday.getFullYear());

        Xrm.Page.getAttribute("new_age").setValue(age);
        Xrm.Page.getAttribute("new_age").setSubmitMode('always');
    }
}

function calculate_age(birth_month, birth_day, birth_year)
{
    today_date = new Date();
    today_year = today_date.getFullYear();
    today_month = today_date.getMonth();
    today_day = today_date.getDate();
    age = today_year - birth_year;

    if (today_month < (birth_month))
    {
        age--;
    }
    if (((birth_month) == today_month) && (today_day < birth_day))
    {
        age--;
    }
    return age;

}

Hope this is help!

Thanks.
Vipin Jaiswal

Thursday, March 7, 2019

You do not have {0} permission to access {1} records.



You might login to Dynamic CRM and face such kind of permission problem. 
This is because you do not have security role assigned by your System Administrator.
The System Administrator only might have assigned a Dynamic 365 license to you. 
But there are further mandatory step to configure user and provide him appropriate security role in Dynamic 365 CRM.

Here are the steps you can refer and ask your system administrator to do in order for you to access Dynamic 365 RM.
  • System Administrator login to Dynamic 365 CRM
  • Navigate to Settings -> Security -> Users


  • Locate the specific user and click on the user to enable Manage Role button




Select an appropriate role and click OK to assign a security role to the user.

After this been done, a user can log on to Dynamic CRM and will be able to access CRM without any issue.

Thanks,
Vipin Jaiswal
vipinjaiswal12@gmail.com