Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

fetchXML and loop through the data set with JavaScript

(0) ShareShare
ReportReport
Posted on by 34

Hi

I used fetchXml to retrieve data from the entity and loop through the data set using JavaScript. However, when I loop through the data, I am getting an empty result (refer to the JAVASCRIPT code below).

Could you advise how i can get each data from the collection?

alert('{{porvinces[i].value}}');  //this line return empty

alert('{{porvinces[0].value}}');  // this line return the right value

<fetch top="50" >
<entity name="stringmap" >
<attribute name="attributevalue" />
<attribute name="displayorder" />
<attribute name="objecttypecodename" />
<attribute name="attributename" />
<attribute name="value" />
<attribute name="objecttypecode" />
<attribute name="langid" />
<attribute name="stringmapid" />
<filter type="and" >
<condition attribute="attributename" operator="eq" value="provincesterritories" />
</filter>
</entity>
</fetch>

$("document").ready(function() {
var entitySize="{{provinces.results.entities.size}}";
var i=0;
var entityObj;

for(i=0;i < entitySize;i++ )
{
alert('{{porvinces[0].value}}');  // i get the right value
alert('{{porvinces[i].value}}');  //this line return empty

}
});

  • Nya Profile Picture
    Nya 29,058 on at
    RE: fetchXML and loop through the data set with JavaScript

    Hi,

    Have you checked the type of i? Is it a number or a string?

     

    Looking forward to your reply.

    Best Regards,

    Nya

  • SivaR Profile Picture
    SivaR 34 on at
    RE: fetchXML and loop through the data set with JavaScript

    entitysize return 10

    in for loop, i can print the number. only if i use in this format '{{porvinces[i].value}}', i am not getting value.

    {% assign porvinces =   reasonEntries.results.entities %}

    $("document").ready(function() {

    var entitySize="{{reasonEntries.results.entities.size}}";

    alert(entitySize); // this line returns 10

    for(i=0;i < entitySize;i++ )

    { alert( i + " number of loop"); // this line retuns value

       alert('{{porvinces[2].value}}' + "  second item"); // this line retuns value

        alert('{{porvinces[i].value}}' + "==increment value==");

    }

    });

    }

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: fetchXML and loop through the data set with JavaScript

    Hi,

    As you can get the right value of {{porvinces[0].value}}, the issue most likely related to the circulation. Have you tried to see the value of the parameter – entitySize, which should not need to be enclosed in quotes?

     

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans