Category: Dynamics CRM 365 Online

Create Auto-Number Attribute In Dynamics CRM 365 Using Organization Service + Simple Console Application

With the Dynamics 365 v9, you can add an auto-number attribute for any entity. Currently, you can add the attribute programmatically. There is no user interface to add this type of attribute.

There are actually two ways of doing this one is using c# code which you can use a console application and other being Web API request.

In  this blog, I will cover the 1st one, and by default this blog will also help you in connecting dynamics CRM 365 with console application.


Create a simple console application

 

  1. Open Visual Studio and click on new project and select console application project type and give it a name as “AutoNumber” and click on OK.



  2. From your solution manager , right click on “References” and click on “Manager nuget package”:




  3. In the search box enter the name as “Microsoft.CrmSdk.CoreAssemblies” , when result comes > select an click on install. It will install the dynamics crm core assemblies reference needed in the application.



  4. Now from your solution explorer click on add references and again select “System.Configuration” , “System.ServiceModel“and “System.Runtime.Serialization assmeblies“.


  5. Use below namespaces:
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Client;
    using Microsoft.Crm.Sdk.Messages;
    using System.Configuration;
    using System.Net;
    using System.ServiceModel.Description;
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Metadata;
  6. Copy paste below code in the application:
 IOrganizationService organizationService = null;

            try
            {
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = ConfigurationManager.AppSettings["Username"];
                clientCredentials.UserName.Password = ConfigurationManager.AppSettings["Password"];

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                
                organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri(ConfigurationManager.AppSettings["CRMUrl"]),
                 null, clientCredentials, null);

                if (organizationService != null)
                {
                    Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;

                    if (userid != Guid.Empty)
                    {
                        Console.WriteLine("Connected to dynamics crm");

                        CreateAttributeRequest widgetSerialNumberAttributeRequest = new CreateAttributeRequest
                        {
                            EntityName = "new_autonumber",
                            Attribute = new StringAttributeMetadata
                            {
                                //Define the format of the attribute
                                AutoNumberFormat = "DPR-{SEQNUM:5}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}",
                                LogicalName = "new_serialnumber",
                                SchemaName = "new_SerialNumber",
                                RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                                MaxLength = 100, // The MaxLength defined for the string attribute must be greater than the length of the AutoNumberFormat value, that is, it should be able to fit in the generated value.
                                DisplayName = new Label("Serial Number", 1033),
                                Description = new Label("Serial Number of the widget.", 1033)
                            }
                        };
                        organizationService.Execute(widgetSerialNumberAttributeRequest);                      
                        Console.WriteLine("Created the autonumber attribute successfully..");
                    }
                }
                else
                {
                    Console.WriteLine("Failed to Established Connection!!!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught - " + ex.Message);
            }
            Console.ReadKey();
        }

 

        7.  In the code above:

            A. change the entitylogical to the name of the entity where you want to create an autonumber field.  
            B. Give the required logical name of the attribute(which you would like to create).
            C. notice the  code line —-   

AutoNumberFormat = "DPR-{SEQNUM:5}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}" 


         In the code above you can actually define what should be the format of your auto number as in example below : 

( Taken from docs.microsoft here : AutoNumber  Format Options)
        
     8. Now in your app.config put below( Insert the correct organization URL , username , password):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="CRMUrl" value="https://organame.api.crm8.dynamics.com/XRMServices/2011/Organization.svc" />
<add key="Username" value="Username" />
<add key="Password" value="Password" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>


     9.  Build your console application( right click on solution and click “Build Solution” and then Run(Start) it:
        

    10. If it gets excuted fine , go to your dynamics CRM and open the entity fields from Settings > customizations > customize the system > entityname> fields. You will notice the field is created:
       
    


   11. Customize the form and add this field to the form post which try to create a record in dynamics crm. I have create two records and could see below:

      


 

     12. Note that you can always update this attrubute if it is created incorrectly by using code given here and using the same application we created :  Update AutoNumber attribute


Conclusion:
We can utilize this feature very well for creating an autonumber field in crm. before this we needed created a plugin which will trigger everytime or a workflow with very complex configuration.

Transaction handling:

“SEQNUM” which is The sequential segment is generated by SQL and hence uniqueness is guaranteed by SQL.

In my next blog – we will create an auto number field with more simpler approach of Web API request.



       
 
          

White Paper – Migrate Microsoft Dynamics CRM 2016 On-Premises to CRM 365 Online v9

This consists of steps/considerations for upgrading dynamics CRM 2016 On-Premises v8.1/8.2 to Dynamics CRM 365 Online v9

I would like to thank Ravi Kashyap for helping me validate the process and Andrew Butenko for his nice blog.

A typical migration process should consist of below steps:

  • First things first – Decide the Dynamics CRM 365 Online Customer Engagement Plan
  • Validate your client side & server side code 
  • Backup your existing Data & Customization (Optional)
  • Deploy Customizations to Dynamics CRM Online Instance
  • Active Directory Synchronization
  • Migrate your data
  • Fix JavaScript & Plugins
  • Validate Sitemap
  • Reporting Options in Dynamics CRM Online 365
  • Test,Test & Test Again
  • Copy Instance

1. Decide the Dynamics CRM 365 Online Customer Engagement Plan


Microsoft offers variety of subscriptions based on the functionality required by the business. Now it can be very confusing in terms of costing. There is a tool available which can be used to estimate your costing of Dynamics CRM online implementation: http://www.infostrat.com/dynamics-365-cost-calculator

However, the Microsoft Pricing page the details are also pretty neat to understand : https://dynamics.microsoft.com/en-in/pricing/


Microsoft Fast Track Program for Online implementation

This is a special assistance provided by Microsoft for the business who are planning for dynamics CRM Online Implementation and purchasing 250+ license where in Microsoft will take care of the migration of Customization + Data for your CRM. Which literally takes all your headache away!
read more about it here : https://www.microsoft.com/en-us/fasttrack/dynamics-365

 


2.Validate your client side & server side code

though your code or script in 8.1 should work in Dynamics CRM Online 9.0, it is recommended that these should be updated to use the latest API. For example Page is deprecated in v9, however deprecation doesn’t mean it will stop working right away, it just means that Microsoft has a plan to vanish it in coming updates/releases.

Now there is a very nice tool available which helps to validate your JavaScript by running in your dynamics crm. This XrmToolBox (details here)plugin will scan your environment and Validates your JavaScript Webresources if they are compatible with Dynamics CRM 365 V9. It will tell which method needs to be replaced with what method. More details can be found here : https://www.powerobjects.com/2018/09/17/upgrade-deprecated-client-apis-dynamics-365-v9/

 

Note down all the issues , even you can start fixing these in the background. Another point to note is Odata should not at all be used to for any CRUD operation in your system and must be replace by Web API.

Now if we talk about server side code/plugins there is not much difference – the only thing  to be done is to use the latest SDK assemblies version 9, all the latest CRM SDK assemblies are available on the nuget store and should be replace otherwise plugins will not be able to run and communicate with your dynamics CRM. Apart from it the solution must be update to use .net framework 4.5.2 minimum.

 

3.Backup your existing data & customization

This step is optional and can be skipped.

This step requires a simple backup of your database of Dynamics CRM Organizaton & keeping them in some place.

Step 1: Open SQL Server and Expand Databases. Right Click on required Organization(*****_MSCRM)  to take Backup and Go to Tasks -> Back Up…
Step 2: Would like to provide the new Destination Backup Path.
Step 3: Select path and provide File Name and click on OK.
Step 4: Click on OK to start backup.

4.Deploy Customizations to Dynamics CRM Online Instance

This is probably the most important step, if you are able to perform this without any hiccups; you have done most of the upgrade work.

Its time you export all customizations from your On-Premise environment. Now do not export default solution/customization from your On-Premise environment, rather create a custom solution and add all your customization in the solution. As Microsoft Dynamics CRM Online doesn’t support default customization import.

Once solution has been exported, open your dynamics CRM Online instance and import the solution.

Generally solution to v9.0 from v8.1 can be imported without any issues. But if any errors come, the real time troubleshooting should be done as it’s unpredictable. So, BE READY FOR MULTIPLE TRY/FAULT ATTEMPTS.  If things doesn’t go well , I would suggest to break down the components and then deploy :

   
      ●  WebResources & OptionSets
      Custom Entities + Dependencies on Standard Entities (like custom view of standard entity used in the subgrid of custom entity form)
        Standard Entities
        Security Roles
        Dashboards & Reports
        Processes & Plugins & Custom Workflow Assemblies
        SiteMap & Application Ribbon

Apart from it Connection Roles, Templates, Field Security Profiles e.t.c can be separated too to avoid “missing dependency error”.

5.Active Directory Synchronization

Transition to dynamics crm online can be really weird and new for the users but doing AD synchronization can definitely comfort them to some extent. If you have a large organization that uses Active Directory to manage your users and groups, setting up Active Directory synchronization will allow you to manage all of your CRM Online users in a central location, avoiding the need to manage multiple user accounts and passwords. In the Office 365 portal, each user record automatically includes user details such as phone number, which is populated from the corresponding user entry in Active Directory. After you assign a CRM license to a user in the Office 365 portal, the user (and all associated details) will appear within the CRM application. If the user’s name or other information is updated in Active Directory, any changes will automatically propagate to CRM.

 

Here are few links to enable this:

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

https://www.crmsoftwareblog.com/2013/07/synchronizing-microsoft-dynamics-crm-online-with-your-active-directory/

6.Migrate your data

Migration of the data is another important aspect of an upgrade after customization.
There multiple options available such as custom .net code( console application) , Scribe, SSIS along with Dynamics CRM Adapters provided. Based on the volume of data, option can be selected.

Kingsway has a “Starter Package” that can be used a foundation to the migration of data from CRM to CRM.

http://www.kingswaysoft.com/downloads/samples/CrmMigrationStarterPack.zip

you can combine Scribe with SSIS for other options such as migrating users. Where in you can get users using SQL query and then create them in dynamics crm online using API. ( we will talk about synchronization of Active Directory with dynamics crm online to be able to let users  use existing logins and email addresses).

 

7.Fix JavaScript & Plugins

Now that you have your customizations and Data in your dynamics CRM instance, Its time to go back to step 2 – Validate client and server side code.
We have discussed briefly there approach of fixing JavaScript and plugin code as what needs to be done.

 

8.Validate Sitemap

Now that you have moved your customizations, you might see weird changes on your dynamics CRM online sitemap.

Few ways to fix your sitemap and design your way again.

Using the build in SiteMap designer in dynamics CRM 365 online : https://www.inogic.com/blog/2018/01/inline-editing-for-sitemap-components-in-dynamics-365-v9-0/

Using SiteMap Editor tool from XRMToolbox: https://www.xrmtoolbox.com/plugins/MsCrmTools.SiteMapEditor/

Manually making changes to sitemap customization xml.

 

9.Reporting Options in Dynamics CRM Online 365

this is also one of the important aspect of dynamics CRM migration. Since you are moving Online/Cloud, your SQL based SSRS reports will not work. As Dynamics CRM 365 Online doesn’t support SQL based reports.

Hence you might want to consider changing each and every report, however changing them is not option here and also not a straight forward process due to various limitations. You might want to explore other reporting options:

● SSRS fetch XML based report – you can very well create fetch XML based reports. It’s very similar to how you create SQL reports and are fully compatible with dynamics CRM 365 Online.

Power BI – lets you create rich, interactive reports and real-time visualizations in Dynamics 365 for Customer Engagement with Power BI dashboards and tiles that you add to your personal dashboards.


See more:
https://docs.microsoft.com/en-us/dynamics365/customer-engagement/basics/add-edit-power-bi-visualizations-dashboard

Excel Templates – Excel provides powerful ways to analyze and present your Dynamics 365 for Customer Engagement data. With Excel templates, you can easily create and share your customized analysis with others in your organization.

See more: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/analyze-your-data-with-excel-templates

 

 

10.Test, Test & Test Again..

You probably had rough days going through the migration process but its not the end until unless you are not fully confident, to gain confidence, you would need a team of testers who can test each and every functionality thoroughly.

While you are on migration – let people create test scripts for each functionality, get them approved by an expert and make sure they touch each and every component of your dynamics CRM.

Create a powerful regression suite – that takes you through end to end huge functionalities i.e. a quote and buy process, lead to invoice process etc.

Don’t hesitate in taking a testing expert with automation experience who can speed up things.
Remember the more you test, the more you gain confidence.

 

11.Copy Instance

once you have verified and everything looks fine – you would probably want one more instance such as a Dev or UAT environment. You can do that within your subscription.
You have two options while copying this instance Dynamics CRM Online:

● Full copy – A full copy includes all application data, users, and customizations from the source instance.
Minimal Copy – A Minimal copy only includes users, customizations, and schema from the source instance.

Read More : https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/copy-instance

 

I hope this helps! 

                                  ****ALL THE VERY BEST****

Attach a static PDF to OOTB D365/CRM Workflow

So a recent requirement put to me was to send an email to customers with a specific attachment.

There was also a requirement to ensure the right people would get the email but that was fairly straight forward and manageable through Advance Find/Fetch XML.

I was quite keen to avoid development of a custom workflow activity or plugin to cater for this business objective.

After some investigating I found a fairly straight forward solution:

  1. Create an email template with the body/dynamic tags you wish to and attach the static attachment(in my case a PDF) here
  2. Create your asynchronous workflow as you normally would with the conditional logic and trigger points
  3. When adding the send email action, choose to use email template and call in the email template within the workflow

Simples :)!

Error While Connecting To CRM Online Using Kingsway SSIS Connector

Issue:

I have recently got this error when i was preparing an SSIS package for Dynamics CRM 365 Online and used Kingsway SSIS connector.

Kingsway1

Resolution:

After digging in further this error is mainly caused by the request and reponse timings,So, when i checked i found out my system time was somehow 5 minutes ahead of the current time, hence the request going to CRM server was of a future time and hence this error showed up.

All i had to do is fix my system time. Sometimes even if your system time is fine, you might still get the error, In that scenario too try to change the time as 5 minutes less.

 

Once i did that -my organisation name popped up without any issue.
kingsway2.png

 

Hope this helps!

Cheers!

 

An unsecured or incorrectly secured fault was received from the other party

Issue :

Recently i have encountered this error when i was trying to connect to Dynamics CRM 365 online.

error1.PNG

 

I digged in further and found a post where couple of suggestions were mentioned :

https://community.dynamics.com/crm/f/117/t/204264

Solution : It was to do with my system settings(Time) – my system time was ahead of the server time. which means the request was going to server with a future time. 

hence i have changed the time in my system clock to be 5 minutes less. Which indeed worked.

 

I hope this helps!

System Form Dependency To A Custom Entity – CheckList

Following checklist should be completed in order to completely remove the all the dependency before exporting the solution and importing to your target environment.

  1. Make sure all relationships are removed ( i.e navigation from left hand side on form editor)
  2. Any Lookup field from that custom entity is removed
  3. The most important and neglected one and for which I find people scratching their heads is when this lookup is removed from the form and even entity is deleted. Still  Get dependency error something like below:dependency.PNG
    Resolution:  The lookup field was being referenced on another lookup which was acting as a “Dependent Lookup”. hence this entity was showing as system form dependency.  So i went to other lookup field —> changed properties and unchecked the option “Show related records”.You can also try to remove that field –> Publish —> add again —-publish.

Hope this helps!

 

Enable “Read” Auditing In Dynamics CRM 365

Let’s agree, we all have been waiting for this feature since quiet long now.

Records “Read” Audit! yes you have heard it right. This feature will let you capture details about who is reading/retrieving the data just like create/update/delete etc.

This feature is available in Dynamics CRM 365 Online  v8 and above.

1

Note : The auditing logs will be available in the Office 365 Security & Compliance Center not in the tradition record audit history in CRM which actually makes sense as it will be gigantic data and shouldn’t be kept inside CRM.

Follow below steps on how to start utilizing this feature:

  1.  To enable auditing please follow below method:
    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/enable-use-comprehensive-auditing#enable-auditing-in-dynamics-365
  2. To see the logs , follow below :
    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/enable-use-comprehensive-auditing#review-your-audit-data-using-reports-in-office-365-security-and-compliance-center

I hope this helps!

How to Create Auto- Number Fields

Requirement for creating an auto number field is very common & achieving them used to be very difficult or unsupported(using third party tools) . Now with Dynamics CRM 365, you can create an auto-number attribute very easily.

At this moment its not available in the UI , you will have to do it programmatically but its  very less and easy code.

following the format which can be achieved :

AutoNumberFormat value Example value
CAR-{SEQNUM:3}-{RANDSTRING:6} CAR-123-AB7LSF
CNR-{RANDSTRING:4}-{SEQNUM:4} CNR-WXYZ-1000
{SEQNUM:6}-#-{RANDSTRING:3} 123456-#-R3V
KA-{SEQNUM:4} KA-0001
{SEQNUM:10} 1234567890
QUO-{SEQNUM:3}#{RANDSTRING:3}#{RANDSTRING:5} QUO-123#ABC#PQ2ST
QUO-{SEQNUM:7}{RANDSTRING:5} QUO-0001000P9G3R
CAS-{SEQNUM:6}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss} CAS-002000-S1P0H0-20170913091544
CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMMddhh}-{RANDSTRING:6} CAS-002002-2017091309-HTZOUR
CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMM}-{RANDSTRING:6}-{DATETIMEUTC:hhmmss} CAS-002000-201709-Z8M2Z6-110901

lets see how this can be done , in this example i am giving my custom organization entity a serial auto numbered field. you can do this both by C# code or Webapi :

C#

CreateAttributeRequest widgetSerialNumberAttributeRequest = new CreateAttributeRequest

            {
             EntityName = "new_organization",
             Attribute = new StringAttributeMetadata
                {

                    //Define the format of the attribute

                    AutoNumberFormat = "ORG-{SEQNUM:3}-{RANDSTRING:6} ",
                    LogicalName = "new_serialnumber",
                    SchemaName = "new_SerialNumber",
                    RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                    MaxLength = 100, // The MaxLength defined for the string attribute must be greater than the length of the AutoNumberFormat value, that is, it should be able to fit in the generated value.
                    DisplayName = new Microsoft.Xrm.Sdk.Label("Serial Number", 1033),
                    Description = new Microsoft.Xrm.Sdk.Label("Serial Number of the widget.", 1033)
                }

            };
            crmService.Execute(widgetSerialNumberAttributeRequest);

As you can see in my request i have given AutoNumberFormat  as ORG-{SEQNUM:3}-{RANDSTRING:6} from the List.

in case you need the full code:

using System;

using System.ServiceModel;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Metadata;

using Microsoft.Xrm.Sdk.Messages;



amespace Microsoft.Crm.Sdk.Samples

    {

        public class FollowupPlugin : IPlugin

        {
            public void Execute(IServiceProvider serviceProvider)
            {
                //Extract the tracing service for use in debugging sandboxed plug-ins.
                ITracingService tracingService =

                    (ITracingService)serviceProvider.GetService(typeof(ITracingService));
               // Obtain the execution context from the service provider.

                IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
            

            CreateAttributeRequest widgetSerialNumberAttributeRequest = new CreateAttributeRequest
            {

                EntityName = "new_organization",
                Attribute = new StringAttributeMetadata

                {
                    //Define the format of the attribute
                    AutoNumberFormat = "ORG-{SEQNUM:3}-{RANDSTRING:6}  ",
                    LogicalName = "new_serialnumber",
                    SchemaName = "new_SerialNumber",
                    RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                    MaxLength = 100, // The MaxLength defined for the string attribute must be greater than the length of the AutoNumberFormat value, that is, it should be able to fit in the generated value.
                    DisplayName = new Microsoft.Xrm.Sdk.Label("Serial Number", 1033),
                    Description = new Microsoft.Xrm.Sdk.Label("Serial Number of the widget.", 1033)
                }
            };

            crmService.Execute(widgetSerialNumberAttributeRequest);
       }

    }

WebAPI

{
 "AttributeType": "String",
 "AttributeTypeName": {
  "Value": "StringType"
 },

 "Description": {
  "@odata.type": "Microsoft.Dynamics.CRM.Label",
  "LocalizedLabels": [
   {
   "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
    "Label": "Serial Number of the widget.",
   "LanguageCode": 1033
   }
  ]
 },

 "DisplayName": {
  "@odata.type": "Microsoft.Dynamics.CRM.Label",
  "LocalizedLabels": [
   {
    "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
    "Label": "Serial Number",
    "LanguageCode": 1033
   }
  ]
 },

 "RequiredLevel": {
  "Value": "None",
  "CanBeChanged": true,
  "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
 },

 "SchemaName": "new_SerialNumber",
 "AutoNumberFormat": "WID-{SEQNUM:5}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}",
 "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
 "FormatName": {
  "Value": "Text"
},
 "MaxLength": 100
}

 

You just have to pass certain headers in the API request such as Content -Type , Application as JSON and the authentication.

Once you have done this – you will see a a new field as new_serialnumber has been created in the system under new entity. Few things:

  1. Put the field on the form
  2. it will be a locked field
  3. it will generate a new number everytime you click on save

it will be something like below:

Untitled

 

I hope this helps!