Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Loop through a WebApi Result

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans