MS Dynamics Portals - Change Lookup Dropdown Text Values?

104 views Asked by At

I have a basic form metadata field referencing a lookup and rendering the lookup as a dropdown. This is a simple task, and works as expected, displaying the Primary Name field as the Text for each item.

In a particular instance though, I'd like to update the Text for each item to display:

{primaryname} + ' - ' + {anotherFieldValue}

or if that other field is an optionset

{primaryname} + ' - ' + {anotherFieldOptionSetTextValue}

Is there a simple way to accomplish this?

1

There are 1 answers

0
suttonb1 On

Since I couldn't find a simple way to accomplish this, here is my solution.

Do a Liquid fetchxml query (myFetch) that returns the same records as the default view used by the lookup. Then use this script to edit the text values of the dropdown:

$(document).ready(function) {
   {% if myFetch %}
      {% for item in myFetch.entities.results %}
         try {
            $('select[id="controlid"]').find('option[value="{{item.id}}"]').text("{{item.name}} - {{item.optionsetfield.label}}");
         }
         catch{}
      {% endfor %}
   {% endif%}
}

If someone has a better way, please let me know!