简体   繁体   中英

How to only select Active Accounts from Dynamics CRM 2011 using SDK?

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?

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
                });

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM