Default values for sn-record-picker when using ng-repeat to display in table format

CatDog
Tera Contributor

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!

3 REPLIES 3

shawna
Tera Guru

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

find_real_file.png  

Then in the html, I just bind the sn-record-picker to each item within the array of c.data.locations 

find_real_file.png

It will display a list of location pickers as below. 

find_real_file.png

 

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. 

 

Jojolo
Kilo Contributor

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

kente
Tera Guru

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>