We can retrieve the data from the Excel file using two ways:
1. OLeDb Connection
2. Interop Library
Here we are going to use Interop Library.
We have a list of contacts in an Excel file named (Contacts.xlsx) with their Record ID, the scenario here is to retrieve the ID from Excel then use the ID to fetch the record from CRM and update the Contacts field “AE Assigned” to yes.
I have implemented this using the C# Console Application. Look at the example:
Steps to implement the above scenario
Step 1: First open Visual Studio and create a new project like shown below.
Step 2: Navigate to Tools then select NuGet Package Manager.
Step 3: Install Microsoft.Office.Interop.Excel.
Step 4: Create a new Class named Login.cs and here is the custom code to log in to your Dynamics CRM.
Step 4: Now, fetch records from the Excel file using this custom code in Program.cs file.
Here I’m retrieving the first column from Excel as it contains the Record ID of Contacts then converting the retrieved ID into Guid. After that with the help of ID, retrieving records from CRM. Then the update operation to update the AE Assigned field.
Step 5: Next is to build the solution, then after running the Command Prompt window will open it like this, here I have displayed the Contact ID and printed a message when a record gets updated.
That’s how we can use Excel files to retrieve data.