Plugin on Pre-Validation Stage in Dynamics 365 CE

Recently we had a requirement to delete the Account record without deleting the associated Contact records.

If we try deleting the account record we’d get the following message box

The relationship definition can’t be updated as well to achieve this

So, we wrote a plugin on the pre-validation stage of pre-delete event of Account, which will retrieve and loop through all the child contact records and set its parent customer field as null.

In case of pre-operation the child records were not available.


public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext pluginContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService organizationService = serviceFactory.CreateOrganizationService(pluginContext.UserId);
EntityReference targetEntity = (EntityReference)pluginContext.InputParameters["Target"];
QueryExpression getContacts = new QueryExpression("contact");
getContacts.Criteria.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, targetEntity.Id));EntityCollection allContacts = organizationService.RetrieveMultiple(getContacts);foreach (Entity contact in allContacts.Entities)
{
Entity contactToBeUpdated = new Entity("contact");
contactToBeUpdated.Id = contact.Id;
contactToBeUpdated.Attributes["parentcustomerid"] = null;
organizationService.Update(contactToBeUpdated);
}}

 

Another practical scenario

https://www.inogic.com/blog/2017/03/plugin-pre-validation-operation-to-show-an-error-message-as-well-as-log-the-error/

Hope it helps..

Alternate Key not getting created on solution import in Dynamics 365

Recently, we moved our Solution from Development to Test. Then on running one of the SSIS Packages we got the below error

The specified key attributes are not a defined key for the entity [4] CRM service call returned an error:

On opening the Entity for customization, and checking for the key, we saw that it was in the Status Pending.

On opening the system job, there was no detail for the error.

We normally get this error, if there are records already available that have duplicate values for that alternate key field. However, in this case, there we no record as this entity was being moved first time in the Test.

Well to just fix this we thought of manually reactivating the key

However, that threw a new error that “Reactivate entity key is only supported for failed job.”

To fix this go to Settings à System Jobs à search for the failed system job and delete them

Now we will see the status as Failed

This time it will allow running the reactivation.

Finally,

Hope it helps..

Upgrading from Dynamics CRM 2016 On-Premise to Dynamics 365

Make sure the Solution is compatible to Dynamics 365 (8.2), for this check the Version Compatibility

https://docs.microsoft.com/en-us/previous-versions/dynamicscrm-2016/developers-guide/gg328109%28v%3dcrm.8%29#version-compatibility

Upgrade the existing CRM 2016 On-Premise Server to CRM 2016 (8.1) for its solution to be compatible with Dynamics 365 Online using cumulative updates.

https://support.microsoft.com/en-gb/help/3142345/microsoft-dynamics-365-onpremise-cumulative-updates

If upgrading from previous version i.e. prior to CRM 2016, use “Migrate by using a new instance of Microsoft SQL Server” approach

https://technet.microsoft.com/en-us/library/hh699669.aspx

https://technet.microsoft.com/en-us/library/hh699747.aspx

Once updated to compatible CRM 2016 On Premise (8.1), go to settings à customizations and export the existing solutions or create a new solution, add all the required solution components to it as unmanaged which will be imported to the new Dynamics 365 online environment.

Create a new Dynamics 365 Online Environment and synchronize it with your existing Active Directory

https://blogs.msdn.microsoft.com/crm/2013/07/18/how-to-synchronize-crm-online-with-your-active-directory/

With solution ready and imported to new Dynamics 365 Online, next step is migration of data.

Consider using a data migration tool like KingswaySoft.

Check out their Migration Starter Pack.

https://www.kingswaysoft.com/blog/2016/09/16/Announcing-Migration-Starter-Pack-for-CRM-Online-and-CRM-On-Premise

or Scribe

https://www.scribesoft.com/solutions/dynamics-365/

Use following tools to update the JavaScript to Version 9.0 of XrmToolBox.

https://www.xrmtoolbox.com/plugins/XrmToolBox.Dynamics365V9JavascriptValidator/

  • Script Finder (to update the form and fields for passing the executionContext)

https://www.xrmtoolbox.com/plugins/MsCrmTools.ScriptsFinder/

https://community.dynamics.com/crm/b/develop1/archive/2017/11/11/executioncontext-hits-the-big-time

Update JavaScript to use Web API.

https://github.com/jlattimer/CRMRESTBuilder

SQL Based report, if possible, needs to be converted to use Fetch XML. Use the following tool to speed up the process.

http://www.sql2fetchxml.com/

If the reports are too complex, plan to use Power BI reports.

https://technet.microsoft.com/en-us/library/dn708055.aspx

Plugin and Custom workflow needs to be updated to run in an isolated environment i.e. sandbox along with references to the latest SDK assemblies.

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/plugin-isolation-trusts-statistics#web-access

https://www.nuget.org/packages/Microsoft.CrmSdk.CoreAssemblies/

If the existing On-Premise is integrated to other applications, make sure they can still talk with new Dynamics 365 Online.

Recurring jobs if needed, can be deployed to Azure as Azure WebJobs.

https://docs.microsoft.com/en-us/azure/app-service/websites-dotnet-deploy-webjobs

Use Hybrid Connection to talk with On-Prem resources.

https://docs.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections

These were some of the points I could quickly think of. Please share your thoughts and experiences in comments. I’d update this list.

Do check out :

Microsoft Dynamics CRM (on-premises) to Microsoft Dynamics
Online Migration Guide

https://download.microsoft.com/download/6/D/6/6D67BDEA-1D67-42B4-A52A-CF13CD547CB5/OPtoCRMOnlineMigration.pdf

Hope it helps..

Error validating profile registration while configuring Microsoft Dynamics 365 Data Export Service

While configuring the Data Export Service we got the below error while validating the profile

It mostly occurs if there is some issue with the connection string specified in the PowerShell Script used for generating the key vault.

Always copy the connection string from the Azure SQL Connection Strings property and double check the username and password provided there. And make sure the user specified has all the required rights.

https://technet.microsoft.com/en-us/library/mt744592.aspx#Anchor_1

Correcting the connection string resulted in successful validation of the export profile.

Hope it helps..

LookupRecordNotAvailable error while using Configuration Migration Tool in Dynamics 365 Customer Engagement

While trying to migrate the record using the Configuration Migration Tool, we were getting error like below in the log

ImportEntity – Result: True – Entity: transactioncurrency – Adding transactioncurrency to the reprocess List as field createdonbehalfby with value 05d52058-eb35-41e8-8af7-dfb7120c4599 – LookupEntity systemuser and Record Id 2655712b-e13b-e711-80fb-5065f38b5691 (SYSTEM) – (action:Update) failed validation for reason code: LookupRecordNotAvailable

As we do not want to migrate the createdonbehalfby field, the easiest fix for this is to remove the field from the schema.

Ideally instead of adding the entire Entity, we should select only those fields whose value we want to migrate in the Schema file.

Hope it helps..

Power BI with Dynamics 365 CE – Dynamics 365 Content Pack

In previous posts we covered

Creating a Power BI Report using Dynamics 365 Online Service.

Publishing it and Showing it inside Dynamics 365 and scheduling its Refresh.

Apart from creating our own Power BI Report another way of quickly be up and running is to use the Content Packs provided by Third Party Service, for e.g. here we will be using Sales Analytics for Dynamics 365 content pack provided by Microsoft.

Login to the Power BI service, click on Get Data, select Services.

Select Apps and choose the Sales Analytics for Dynamics 365 from the AppSource.

If we search for Dynamics 365, we can see around 15 Apps provided by Microsoft.

Back into our Sales Analytics for Dynamics 365 App, when we click on Get in now we are presented with the option where we need to Specify the URL of our Dynamics CRM Online Service and Fiscal Year End Month Number for that organization.

In the next screen, we need to select OAuth2 as the authentication method and followed by signing in.

This installs the app which would be available in the Apps section.

Clicking on the installed Sales Analytics App opens the Dashboard

Clicking on Ask a question about your data inside Dashboard allows us to analyze the data by allowing us to choose the criteria

Here we have filtered the accounts by created on by month along with the owner

Also, we can see around 10 different reports created inside that app.

  • Sales Performance
  • Sales Leaderboard
  • Win/Loss Analysis
  • Top Won/Lost Details
  • Sales Pipeline
  • Sales Pipeline Dashboard
  • Sales Activity
  • Open Activities
  • Lead Analysis
  • Account Analysis

Similarly, we can create our own Content Packs to be shared with either specific group or with the entire organization.

Click on settings gear inside Power BI Service and select Create Content Pack

Here we are creating a content pack choosing the Dashboard, Reports and the Dataset that we created earlier in the previous posts.

Once published, the user 2 can click on Get Data and search for and can see the content pack.

Clicking on Connect adds the Dashboard, Report, and the corresponding Dataset to the My Workspace of the user. Only the user who had created the content pack can edit the artifacts that are part of Content Pack, however, the other user of the organization can save a copy of it and can work on it.

More on it

https://docs.microsoft.com/en-us/power-bi/service-organizational-content-pack-manage-update-delete

Hope it helps..

Power BI with Dynamics 365 CE – Refreshing the Dataset

In the previous post, we used Dynamics 365 Dashboard and Power BI Tile to show Power BI Dashboard and report inside Dynamics 365.

https://nishantrana.me/2018/08/20/power-bi-with-dynamics-365-ce-showing-power-bi-dashboard-tile-inside-dynamics-365-ce/

Now as a next step, we want to make sure that the users are looking at the latest data possible inside the Dashboard\Reports.

In case of Online Services like Dynamics 365 (Online), we have the option to manually Refresh the data.

To see it in action, let us create a lead record in Dynamics 365.

This is how our Dashboard looks like for now à

Now back in Power BI Service right, click on ellipsis for the Dataset and select Refresh Now.

We can see the newly created lead in our Power BI Report inside Power BI Service and Dynamics 365 CE.

The other option we have is to Schedule the refresh.

Navigate to the Dataset and select Schedule Refresh

We can select the Refresh Frequency as Daily or Weekly.

And we can set it to refresh up to 8 times per day as shown below.

With Power BI Pro License, we can complete the scheduled refresh 8 times a day whereas the Power BI Premium allows the refresh up to 48 times per day.

https://powerbi.microsoft.com/en-us/power-bi-premium/

Some helpful links

https://docs.microsoft.com/en-us/power-bi/refresh-scheduled-refresh

https://www.powerobjects.com/2018/01/11/power-bi-data-refresh-performance/

https://crmtipoftheday.com/category/power-bi/

Hope it helps..

Power BI with Dynamics 365 CE – Publishing Power BI Report to the web

In the previous post, we learned how to create a simple Power BI Report using Power BI Desktop

https://nishantrana.me/2018/08/20/power-bi-with-dynamics-365-ce-creating-report/

Now let us publish the report to Power BI Service from within the Power BI Desktop.

To do so, select the Publish button

Publish window will ask us to save the report file (if not saved) before we could publish it.

Here we are publishing it to the default “My Workspace” app workspace within Power BI Service.

Publishing the report from Power BI Desktop publishes both the report and dataset associated to it in the Power BI Service. We can think of DataSet as the Database.

After successful publish we can see the Report and Dataset being added inside the Power BI Service (https://app.powerbi.com)

From with Power BI Service, we have the option of Publishing the report on Web so that it could be accessed by anyone having that URL.

To do so,

Select File
à
Publish to Web to publish it.

The Embed dialog box pops up as shown below with all the information.

Clicking on Create Embed Code will open the confirmation dialog box, that shows the potential risk associated with sharing the information over the internet.

Here, clicking on Publish generates the link for the report and also the HTML code which can be used for embedding it within an IFrame.

Within Dynamics 365 CE, we can use this public URL to show it inside the IFrame component of the Dashboard.

The report within Dynamics 365 CE’s Dashboard.

Next, we will see how to create Dashboard from the reports created and how to share them with other users and how to use the Power BI Dashboard and Power BI Tiles feature of Dynamics 365.

Hope it helps.

Power BI with Dynamics 365 CE – Creating Power BI Report

To begin with, let us first create a Dynamics 365 Trial.

https://trials.dynamics.com/

After our CRM trial is setup up successfully, we will install the OOB Sample Data which we would be using for creating the Power BI report.

Next, we need to create a free trial for the above user to use Power BI Service.

Go to Power BI site, and click on Start Free to get started.

Use the same user account (trial) that was used to set up the Dynamics 365 trial.

https://powerbi.microsoft.com/en-us

Note: If we already have an organization account with Power BI License we can use it to log in to Power BI else can associate a free trial to the same organization account instead of creating a new one. The gmail, hotmail, yahoo etc personal account are not allowed. https://app.powerbi.com/.

Download the Power BI Desktop as well as click on Try Free.

Power BI Desktop is basically a feature rich windows application that allows us to get data from various services online or on-premise and develop Dashboard and Reports efficiently.

The alternate way to download is through Microsoft Downloads siteà

https://www.microsoft.com/en-us/download/details.aspx?id=45331

After installing it and signing in and click on Get Data ribbon button to connect to the Dynamics CRM Online.

Select Dynamics 365 Online as the Online Services to connect to.

Specify the Web API URL of the instance.

Copy it from Customization à Developer Resources

Select the Organization Account and Sign in to the CRM Instance.

In the Navigator window, we have searched Lead entity and clicked on Edit to select the columns that we need for our sample report.

In the Query Editor window, click on “Choose Columns“, we have selected the Revenue, Created On, Subject and Owning
User field to be used for the report.

Now to get the Full Name of the system user for Owning User, expand that column, and select Full Name as the value to be displayed as shown below.

Click on Close and Apply to apply the changes to the query and to go back to the main editor.

Back in the main editor, we can see the fields added.

Now from the Visualizations section pick any of chart type.

Here we have picked a Stacked Bar Chart to start with. We can drag the fields and specify Area, Legend, and Value and also use the Filters section to generate the report as shown below.

The report after adding the fields à

Similarly, we can add our filter in the FILTER section to filter the records further as shown below

We can also add multiple charts in the report by selecting it from the Visualizations section.

For e.g. here we have used a Clustered Column chart to see all the leads based on Owner and Created On Date.

This completes the creation of simple reports which uses Dynamics 365 Online as Data Source.

In the next post, we’d publish this report to Power BI Service and display it within Dynamics 365 CE.

https://nishantrana.me/2018/08/20/power-bi-with-dynamics-365-ce-publishing-power-bi-report-to-the-web/

Hope it helps..

Maximum File Size Exceeded while using Export to Excel in Dynamics 365 CE

We got this error while trying to export around 70K data through export to excel in Dynamics 365 CE.

Log file gave us detail of the error i.e. Excel file exceeded size lime of 4 MB.

One workaround is to export small set of data (page wise) by applying some order criteria (either in the Grid or through Advanced Find)

Or better use the wonderful Export to Excel tool in XrmToolBox

https://dreamingincrm.com/2015/05/30/new-xrmtoolbox-plugin-export-to-excel/

It took few mins to export the records in excel and the file size was close to 19 MB.

Hope it helps..