Skip to main content

Posts

D365 Remove contact or update contact information

We all come across the requirements where the contact information for the customer is entered in a wrongly manner or there's whole set of records where the information provided is completely garbage. For me it was Email and Mobile. So we extracted data and narrowed it down to list of customers with garbage values. For this I have prepared one csv file mainly consisting four columns. 1) Account 2) Garbage info Email/Mobile 3) Identifier Email/Mobile 4) Add for modifying existing number. Below is the code to call the same from RunnableClass class CustomerDataCleanupEmailAndPhone {     /// <summary>     /// Runs the class with the specified arguments.     /// </summary>     /// <param name = "_args">The specified arguments.</param>     public static void main(Args _args)     {         #define.LocationRoleName('Collection')         AsciiStreamIo      ...

Converting item type in D365 through code

 Well recently I came across an issue where user had created more than 100 items in productions with wrong type. The standard out of the functionality does not allow to convert the item type if its released. Deleting is also not possible. So we are stuck with an option of disabling the item and creating new once with correct type. But the limitation here is than we would have to come with new sku code where its similar to original code but not exact as it is used. So I wrote the code convert the item type through X++ which resolved our issue. Below is the code to perform this task. I am using csv file to bulk update the items and changing item type from service to item in this example. public static void main(Args _args) {         AsciiStreamIo                                   file;         Array                ...

D365 Finance and operations Performance Key Patterns and Anti patterns

 

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...