0
votes

I am using this C# SDK to get data from Dynamics CRM 2011: https://msdn.microsoft.com/en-us/library/gg695803(v=crm.5).aspx

I need to read all the Accounts from it, the problem is, there are many accounts that are deactivated.

To get the accounts I am using the following code:

var accounts = xrm.AccountSet
                .Select(acc => new
                {
                    name = acc.Name,
                    guid = acc.AccountId,
                    parent = acc.ParentAccountId,
                    number = acc.AccountNumber,
                    website = acc.WebSiteURL,
                });

This way has been suggested in this question: Retrieve list of all accounts in CRM through C#?

The problem is, this gets me all the accounts, both active and deactivated accounts. Is there any way to differentiate betweet those two?

2

2 Answers

4
votes

Try something like:

var accounts = xrm.AccountSet.Where(acc => acc.StatusCode.Value == 0)
                .Select(acc => new
                {
                    name = acc.Name,
                    guid = acc.AccountId,
                    parent = acc.ParentAccountId,
                    number = acc.AccountNumber,
                    website = acc.WebSiteURL,

                    status = acc.StatusCode
                });
0
votes

For anyone wondering, I found the solution.

There is a StatusCode Field for each Account. Just extract it and check its value later.

var accounts = xrm.AccountSet
                .Select(acc => new
                {
                    name = acc.Name,
                    guid = acc.AccountId,
                    parent = acc.ParentAccountId,
                    number = acc.AccountNumber,
                    website = acc.WebSiteURL,

                    status = acc.StatusCode
                });

Is there any other way?