How to dynamically populate a drop down in service portal widget

Bruler1230
Tera Expert

I need to add a dropdown to a widget in the service portal. This dropdown will need to pull the values from a field on the sys_user table. The values in this field need to populate into the dropdown list. I know that this will require some coordination between the html, client, and server scripts for the widget. Does anyone have any examples of how to pull values from a field on a table and populate them in a dropdown in a widget on the service portal?

thanks

5 REPLIES 5

So your server script will result in something like:

["value 1", "value 2", "value 3"]

 

Your ng-repeat then accesses each of those and sets "item" each time. What you have in each loop then is:

loop 1: item = "value 1"

loop 2: item = "value 2"

loop 3: item = "value 3"

 

You then set the options through the "item as item.label" part. This will cause the select option to be:

<option value="item">{{item.label}}</option>

 

Which then actually maps to:

 <option value="value 1">undefined</option>

 

This is because the property "label" does not exist on the string "value 1". You should instead just have:

<select
  ng-model="c.selectedOption"
  ng-options="item as item for item in c.data.values"
  class="form-control"
/>

 

I have changed two things.

  1. ng-model: This will store the selected value, rather that the array.
  2. ng-options: item.label changed to just item

 

Please mark as correct if this solves your issue.