Pavel Kohout
Pavel Kohout

Reputation: 43

MS Dynamics 365 CRM online - dump entity

I'm a newbie in Dynamics 365. We are using Dynamics 365 CRM online version. I need to dump a couple of entities to our local SQL server.

I've found many examples, but not with the entire entity (including lookup columns).

What is not working for me in this (most relevant) sample:

  1. I need a list of all columns (Do I really need to specify the complete column list in new Contact{}?)

  2. Get lookup values in result instead of IDs (guids)

                 `var orgContext = new OrganizationServiceContext(service);
                 // Retrieve the Contact records that we created previously.
                 List<Contact> contacts = (from c in orgContext.CreateQuery<Contact>()
                                           where c.Address1_City == "New York"
                                           select new Contact
                                           {
                                               ContactId = c.ContactId,
                                               FirstName = c.FirstName,
                                               LastName = c.LastName
                                           }).ToList<Contact>();
                 Console.Write("Contacts retrieved, ");'
    

Upvotes: 1

Views: 692

Answers (2)

Though what you’re doing is good practice, which is having defined list of attributes being mentioned in select list, you can select all the attributes by using below syntax. It’s worth to mention that this will have huge performance impact.

List<Contact> contacts = (from c in orgContext.CreateQuery<Contact>()
                                   where c.Address1_City == "New York"
                                   select c).ToList<Contact>();

Coming to your next question - getting lookup field, for that you can use join. For ex. Getting primary contact lookup from account using below syntax. This uses primary key and foreign key between entities to join.

var accountQuery = from account in context.CreateQuery("account")
                   join contact in context.CreateQuery("contact")
                   on account["primarycontactid"] equals contact["contactid"]
                   where account["name"] ==   "Some Company Name"
                    select new {
                           Name = account["name"],
                           Email = account["emailaddress1"],
                           Manager = contact
                      };

foreach (var account in accountQuery)
{
    Console.WriteLine(account.Name + " is run by: " + account.Manager["fullname"]);
}

Read more

Querying using LINQ is one way, there are other ways like web api, fetchxml and query expression to do the same job. You have to still do capture the last run time of your dumping job and filtering delta data using createdon and modifiedon time stamp greater than last run time stamp.

Needless to say, Activity is the most cumbersome entity involving multiple tables as Activity pointer, Activity party, etc.

Upvotes: 1

AnkUser
AnkUser

Reputation: 5531

you can very easily do so with Excel Export feature from Dynamics 365 (CRM)

Simply add all Columns to an advanced find view.

  1. Advanced Find Button

  2. Entity selector (look for)

  3. Edit Columns

  4. Add all Columns to View (see separate picture below for more instructions).

  5. View Results

enter image description here

enter image description here

If you have more than 100000 records you might hit the limit.

"We're about to generate your Dynamics 365 data in an Excel file (more than 5000 records). If there are more than 100000 records, only the first 100000 will be exported."

In addition to buypass the 100000 limit you can use Export to Excel Tool from XRM Toolbox which can help you get all the records without any coding.

Upvotes: 1

Related Questions