Populate HTML controls to update option set / choice fields with the Portal Web API

<!-- Step 1 - Retrieve distinct values in status reason or option set field from all records in Dataverse -->
{% fetchxml statusreason_query %}
<fetch distinct="true" >
  <entity name="musdyn_track" >
    <attribute name="statuscode" />
  </entity>
</fetch>
{% endfetchxml %}

<!-- Step 2 - Populate the HTML form control akak dropdown list, using the numeric option set value as value and the option set label as label
Note - this is comparing each status reason in this query to the selected status reason in the main query, a list of music tracks -->
<select id="statuscode">
{% for statusreason in statusreason_query.results.entities %}
  <option value="{{ statusreason.statuscode.value }}" {% if statusreason.statuscode.value == trackresult.statuscode.id %}selected{% endif %}> {{ statusreason.statuscode.label }}</option>
{% endfor %}
</select>

<!-- Step 3 - Example format to update the field using the Portal Web API -->
"statuscode": $('select[id="statuscode"] option:selected').val()
Franco Musso