Skip to main content

Posts

Showing posts from 2018

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");             String                                    bdate;             Int32                                     rowcount = dataGrid.SelectedItems.Count;             DataRowView                      rw;                      AccountManager     

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();                 filter1.Conditions.Add(condition1);                 query.Criteria.AddFilter(filter1);                         EntityCollection accountname = _service.RetrieveMultiple(query); Other example with contact entity.               QueryExpression query = new Qu

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 serviceUri                                 = new Uri(SoapOrgServiceUri);                 OrganizationServiceProxy proxy   = new OrganizationServiceProxy(serviceUri, null, credentials, null);                 proxy.EnableProxyTypes();                 _service                                           = (IOrganizationService)proxy;             }             catch (Exception

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,custTable.name()));      }    } } Happy daxing!!!

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

A reference to 'Dynamics.AX.XXXXX, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is required to compile this module.

The error "A reference to 'Dynamics.AX.Directory, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is required to compile this module." came on when i was building the project in visual studio. This error is thrown when the model is missing any reference which are needed to build the project. To update rectify this error we need to update the model. To do that go to "Dynamics 365 > Model Management > Update model parameter" A new window will open the model you want to update. Here i am selecting "Development" which i have created. Then click on next. On "Select referenced packages" select the missing packages which ones is throwing error. Here i have selected the "Directory" packages as they are the once throwing error. Select the packages. After selecting the packages click on "Next". And Click on "Finish". Rebuild the project and you are good to go.

Renaming the primary key through code in D365 finance and operations.

Below code will be useful to update the primary key field value in finance and operations. To do that use runnable class to execute the code. class VendAccountRename {          /// <summary>     /// Runs the class with the specified arguments.     /// </summary>     /// <param name = "_args">The specified arguments.</param>     public static void main(Args _args)     {              VendTable vendTableupdate;         ttsbegin;                     select firstonly vendTableupdate where  vendTableupdate.AccountNum == '1002';                                 if(vendTableupdate)             {                 vendTableupdate.AccountNum = 'US-1002';                 vendTableupdate.renamePrimaryKey();                 info("Record updated");             }        select firstonly vendTableupdate where  vendTableupdate.AccountNum == 'US-1002';         info(vendTableupdate.AccountNum);     } } Ha

Renaming primary key field in D365 finance and operations

In ax finance and operations there is a functionality for renaming the primary key field from  front end. For example for Vendor account. Go to all vendor account form. Go to "Options" tab. Click on "Recordinfo". A new side window will open. Click on rename. A new rename window will open. Enter the account number you want the record to be updated as. Here i am using "US-1001". Then click ok. The system will prompt to confirm. Click "Yes". The system will update the record. You can see that in the form. And all the related transactions will be updated as well. To check that you can check with the "Transactions". To check that go to "Vendor" tab and click on "Transaction". New form with the transaction list will open for the Vendor. Happy daxing!!!

Setting company for code execution in D365 finance and operations

In dynamics ax 2012 and 2009 to set the company while executed the code we used to select the company from the bottom screen option. But in new Dynamics 365 for finance and operations for code execution we have to set it at the project property by default it is 'DAT'. To do this go to project and right click and click on properties. A new window will be opened. Set the property as shown in image.  Other way to do this is to use code to change the property. By default the company is 'DAT'. So to execute a code where we want to select a particular company and select a vendor, use below code. We will be using change company function which has been available for all the versions of ax. For this create a runnable class. public static void main(Args _args)     {              VendTable vendTable;         ttsbegin;         info("Company info");         info(vendTableupdate.DataAreaId);            changecompany('USMF')         {          

Creating models for new development in D365 finance and operations

For new development it is advisable to create a new model files. So that all the development done is stored in the model file and moving code from one environment to other environment is easy. In visual studio Go to "Dynamics 365>Model Management>Create model"  Once you select the create model option. New screen will appear asking you fill in the information related to new model. Once you are done with filling the information click on "Next".Where there will be two options available for selection. Select option based on your requirement. Mostly we will be selecting the "Create new package" option. But if var or isv layers needs to be modified you might want to select second option. If you select second option then specify the package you want to modify from the drop down list. Then click next.It show the information which you have entered and selected. Then click on "Finish" to create model file.

Setting up Dynamics 365 for finance and operations

Hi, As i have recently started D365 development and exploring the new ax version. It seems that most of the people are still struggling with the VM setup. I am sharing a link here which was very help full to me when i started doing my own setup. https://www.bootes.co/en/articles/first-time-configuration-of-a-microsoft-dynamics-for-finance-and-operations-virtual-machine-onebox.aspx Hope this will be helpfull to others as well. Happy daxing!!!