web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Loop through a WebApi Result

(0) ShareShare
ReportReport
Posted on by

Anytime, I try to loop the WebAPI(Json result), I always get the first value in the api printed the number of count of the result.

If I have 50 results in the Web Api query the first company(eg. ABC Corp) will be printed 50x. 

Here is a sample code below, I am using to test from https://github.com/davidyack/Xrm.Tools.CRMWebAPI/tree/master/dotnet:

string fetchXml = "<fetch mapping='logical'><entity name='account'><attribute name='accountid'/><attribute name='name'/></entity></fetch>";

var fetchResults = await api .Result.Item2.GetList("accounts", QueryOptions: new CRMGetListOptions() { FetchXml = fetchXml });

foreach (var record in fetchResults.List){
      foreach (var account in record){
         _accountRecord.accountIdNumber = account.Value.ToString();
         _account.Add(_accountRecord);
                             }
                     }

I would like to be able to pint out each company/account name our DynamicsCrmOnline.


Thank you in advance,

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans