Default values for sn-record-picker when using ng-repeat to display in table format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 12:06 PM
How do you set the default values for a sn reference field (ex: sn-record-picker) when using the angular directive ng-repeat?
You would need some sort of way to set each of those javascript objects' values (displayValue & value) dynamically and bind them to their HTML field names, which would have to be dynamic as well else all the record-picker fields would have the same default values.
Thanks!
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 04:06 PM
It is easy to set up the default value.
As long as you can return an array of objects, you can bind the array to the ng-repeat. For example, I returned a location array to the client side: c.data.locations
Then in the html, I just bind the sn-record-picker to each item within the array of c.data.locations
It will display a list of location pickers as below.
The challenge part is how to only update the record that is picked/updated. You will need to have a way to track the sys id of the updated record get the detail of that record from server.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2019 01:54 PM
Hi Shawna,
Can you elaborate on this? Part of the screenshot is missing for the HTML. How about if I just want to set the default value of just one record picker field?
Thanks,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 03:57 AM
Don't know if this still is relevant - but here is a way. 🙂
You can define it in the Server Script and then use that as the "field" in the HTML
Server Script
data.items = [];
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
var obj = {};
obj.test = {};
obj.test.displayValue = gr.getDisplayValue('name');
obj.test.value = gr.getValue('sys_id');
obj.test.name = "something";
data.items.push(obj);
HTML
<div ng-repeat="item in data.items">
<sn-record-picker field="item.test" table="'sys_user'" value-field="'sys_id'" display-field="'name'" search-fields="'name,user_name'"></sn-record-picker>
</div>