Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Is it possible to iterate an object that was fetched

Posted on by 645

I fetched a record with all it's fields - USING FETCH, and I need to iterate the fields, and according to each field to do something in my code, is it possible ?

a code for example:

xml ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>"
xml += "<entity name='game'>"
xml += " <all-attributes />"
xml += "<order attribute='modifiedon' descending='true' />" 
xml += "<filter type='and'>"
xml += "<condition attribute='gameid' operator='eq' value='123' />"  
xml += "</filter> </entity></fetch>"
 
//here I get the object I need the code works fine
var ret = myJS.ExecuteFetchRequest(xml);

for(i=0;ret[0].???;i++){

//get a specific field value and do something with it

}

I want to loop ret[0] - the object, but I can't find how... is it possible?

I tried to parse it using json and loop it from an array but ti didn't went well (if some one has an example to convert it to any array it will be helpful as well)..

*This post is locked for comments

  • Verified answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Is it possible to iterate an object that was fetched

    I am not sure what data type is returned by ret, but it would be something like:

    for(i=0;i < ret.length;i++)

    or

    for(i=0;i < ret.results.length;i++)

    add debugger before your for loop and open F12 developer tools to see what is returned from your ExecuteFetchRequest

    Hope this helps.

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Is it possible to iterate an object that was fetched

    As you're using client script, I expect myJS.ExecuteFetchRequest is a custom function, and the way you process the results will depend on how that function returns the results - can you post the definition of that function ?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans