For Loop – Populate an Audio Player

<!-- Step 1: Retrieve the playlist tracks (link table / intersection entity) related to this playlist, along with the track records (retrieve multiple) -->
{% fetchxml tracks_query %}
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="musdyn_playlisttrack">
    <attribute name="musdyn_name" />
    <attribute name="musdyn_track" />
    <attribute name="musdyn_order" />
    <attribute name="musdyn_playlisttrackid" />
    <order attribute="musdyn_order" descending="false" />
    <filter type="and">
      <condition attribute="musdyn_playlist" operator="eq" uitype="musdyn_playlist" value="{{ id }}" />
    </filter>
    <link-entity name="musdyn_track" from="musdyn_trackid" to="musdyn_track" visible="false" link-type="outer" alias="track">
      <attribute name="musdyn_name" />
      <attribute name="musdyn_mainartist" />
      <attribute name="musdyn_explicit" />
      <attribute name="musdyn_duration" />
      <attribute name="musdyn_albumfirstreleasedon" />
      <attribute name="musdyn_artworknoteguid" />
      <attribute name="musdyn_audionoteguid" />
    </link-entity>
  </entity>
</fetch>
{% endfetchxml %}

<!-- Step 2: Populate the JSON to feed the audio player (using the jAudio plugin) -->
<script>
(function(){
  // Populate the playlist with results from the tracks query
  var t = {
    playlist: [
        // Loop through each result in the tracks query
        {% for result in tracks_query.results.entities %}    
    {
      // Set the file to be played based on the track's Audio Note GUID field
      file: "/_entity/annotation/{{ result['track.musdyn_audionoteguid'] }}",
     // If the track's Artwork Note GUID field is populated...
      {% if result['track.musdyn_artworknoteguid'].size %}
      // ...Set the thumbnail image based on the track's Artwork Note GUID field
      thumb: "/_entity/annotation/{{ result['track.musdyn_artworknoteguid'] }}",
      // Otherwise, set the thumbnail to the Artwork Not Found web file as a fallback
      {% else %}
      thumb: "https://songify.powerappsportals.com/artwork-not-found.svg",
            {% endif %}
      trackName: "{{ result['track.musdyn_name'] }}",
      trackArtist: "{{ result['track.musdyn_mainartist'].name }}",
      trackAlbum: "{{ result['track.musdyn_albumfirstreleasedon'].name }}"
    }{% unless forloop.last %},{% endunless %}
    {% endfor %}
  ]
}
</script>
Franco Musso