Skip to main content

Posts

Deleting Audit history change records through c#

Mainly I had this requirement where I had to delete audit log to shrink the database size so that it come back within log capacity threshold.  Below is the code for the DeleteRecordChangeHistoryRequest() method usage.  Here I am looping through the records to delete the changed history for a particular entity in my case it is "Customer Asset". static void Main(string[] args) { try {  IOrganizationService _service;  ClientCredentials credentials = new ClientCredentials();  credentials.UserName.UserName = "username";  credentials.UserName.Password = "pwd"; Uri serviceUri = new Uri(@"soapurl"); OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null);  proxy.EnableProxyTypes();   _service = (IOrganizationService)proxy; //fetchXML for getting entity  string fetchXML = @"<fetch mapping='logical'>                              ...

Inserting or updating bulk records in CRM 365 through C#

For some scenarios we would be having some requirements where multiple records needs to be created which can take number of iterations. To user service.create() method would affect the performance significantly. So we need to executemultiple request. Below is the code for the executemultiple() method usage. To create contact. Same can be used for other entities as well. Here i am selecting record from grid and looping through the selected records.             Entity                                    contact = new Entity();             EntityReferenceCollection   relatedEntities = new EntityReferenceCollection();             Relationship                          relationship = new Relationship("account_primary_contact"); ...

Retrieving records from CRM 365 through c#

There are scenarios where you would want to retrieve records based on some condition. To do that with the use of C#,below code can be used. For example i have used account entity.                 QueryExpression query = new QueryExpression                { EntityName = "account", ColumnSet = new ColumnSet("name", "accountid") };                         ConditionExpression condition1 = new ConditionExpression();                 condition1.AttributeName = "name";                 condition1.Operator = ConditionOperator.Equal;                 condition1.Values.Add("Your filter value");                 FilterExpression filter1 = new FilterExpression();         ...

Connecting to CRM 365 through C#

To logging in to CRM 365 through c# we need to use below code. For this purpose i have created a method. After adding the reference libraries in the project used below code to login.   public static void ConnectToMSCRM(string UserName, string Password, string SoapOrgServiceUri)         {             try             {                 IOrganizationService                      _service;                 ClientCredentials credentials         = new ClientCredentials();                 credentials.UserName.UserName  = UserName;                 credentials.UserName.Password    = Password;                 Uri...

Installing libraries for Dynamics CRM 365 development

To do the customization for Dynamics CRM 365 and to add new forms with functionality we need to install nuget in visual studio. Previously we used to download the CRM SDK for development. Now its not the same for 365. For this tutorial. Create a new project where you will be adding your code and customization. I am creating a WPF application for this scenario. Once the project is created, go to "References" node and right click. And click on "Manage NuGet Packages". New window will be opened. Search for "Microsoft.CrmSdk.CoreAssemblies v9.0.2.4" and "Microsoft.CrmSdk.CoreAssemblies v9.0.2.4" these are the main assemblies i am using for my example. You can search for other as well and click on install. Once you do the installation. system will ask you to confirm and once you do that you will be able to use the library in your code.You can see the newly added library to "References" node. Happy D365.

Using macro in query as condition in D365 finance and operations

Those who are familiar with the macro in ax will know that the macro's are used when the user/system should not be able to change the value.The values should remain constant. In finance and operations we can define macro and use it in the select query. For this example create a macro with below condition in it. Here i have created #CustomerBlocked with below condition. %1.Blocked ==  CustVendorBlocked::All Now we will be using the macro in the code. For this create a runnable class called BlockedCustomer. Below is the code for the class. class BlockedCustomer {           public static void main(Args _args)    {             CustTable       custTable;      while select custTable             where #CustomerBlocked (custTable)      {       info(strFmt("%1 - %2",custTable.AccountNum,custTabl...

Error 500 on the server for D365 finance and operations

While working on D365 finance and operations one fine day i came across the error 500. There are many reasons for this server. Below link can help you if encounter the same issue. https://community.dynamics.com/ax/f/33/t/195422 If any of solutions does not work for you then you might need to check if there are any newly added objects through code and they might be causing the issue. Try to remove them build and synchronize them with the database. https://community.dynamics.com/ax/b/axdilip/archive/2017/01/05/dynamics-365-for-operations-troubleshooting-http-500-httpcompileexception-error To debug more you can use solution provided in below link. https://www.linkedin.com/pulse/ax7-500-error-shashi-kant-yadav In my case the issue was related to the certificate expiration. To check the expired certificate on the server we can go to "Certificate Management Console" and see the certificates expiration date. To check this is power shell open "Windows PowerS...