Populate HTML controls to update Lookup fields with the Portal Web API

<!-- Step 1: Query Artists to populate the Main Artist and Featuring Artist drop-downs -->
{% fetchxml artists_query %}
  <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
    <entity name="musdyn_artist">
      <attribute name="musdyn_name" />
      <attribute name="musdyn_artistid" />
      <order attribute="musdyn_name" descending="false" />
      <filter type="and">
        <condition attribute="statuscode" operator="eq" value="1" />
      </filter>
    </entity>
  </fetch>
{% endfetchxml %}

<!-- Step 2: Populate a HTML select form control (aka a dropdown list) using the GUID as the value and the record name as the label -->
<select id="musdyn_mainartist">
{% for artistresult in artists_query.results.entities %}
  <option value="{{ artistresult.musdyn_artistid }}" {% if artistresult.musdyn_artistid == result.musdyn_mainartist.id %}selected{% endif %}> {{ artistresult.musdyn_name }}</option>
{% endfor %}
</select>

<!-- The format to populate that field in the portal Web API - assuming there's only one instance of the select field on the web page -->
"musdyn_mainartist@odata.bind":"/musdyn_artists(" + $('select[id="musdyn_mainartist"] option:selected').val() + ")",
Franco Musso