How do I set a default value for snRecordPicker directive?

joanmarisse
Tera Expert

Hi,

I have an sn-record-picker that reference to user table.

I want to set the default value upon onload to the current logged in user.

Please help.

<sn-record-picker field="caller" table="'sys_user'" display-field="'name'" display-fields="'email'"

              default-query="'active=true'"

              value-field="'sys_id'" search-fields="'name'" page-size="100" >

  </sn-record-picker>

Thanks!

6 REPLIES 6

larstange
Mega Sage

Hi



The sn-record picker is bound to an object in the data model. eg. field = "c.caller".



In the client script you define this object



c.caller = {


displayValue: c.data.caller_dv,


value: c.caller,


name: 'caller'


};



Then in your server script, you simply specify the default values - you could get them from the widget options or hardcode them or whatever.



data.caller_dv = [user sys_id];


data.caller = [user display name];


I have the following that is not working for me.



HTML ==========


              <sn-record-picker


              field="c.obo"


              table="'sys_user'"


              display-fields="'name,email'"


              default-query="'active=true^emailISNOTEMPTY^nameISNOTEMPTY'"


              value-field="'sys_id'"


              search-fields="'name'"


              page-size="20">


              </sn-record-picker>


Client script =============


      c.obo = {


              displayValue: $scope.data.obo_gv,


              value: $scope.data.obo,


              name: 'obo'


      }


Server Script ===========


data.obo = gs.getUserID();


data.obo_gv = gs.getUserDisplayName();



Instead of setting the value to a user object, it sets the display field. See the attached image.


Screen Shot 2017-03-15 at 14.58.58.png


I need to use 2 sn-record-picker fields and based on them need to do a submit action in server side, issue is i am only getting one value from caller at a time. How do i attach a label or ng_model or class to sn-record-picker to get 2 distinct values?

console.log(evt) or (parms) doesnt show any field name, all is caller, i did tried id but left the idea as it might not be reliable? plz advice.

larstange
Mega Sage

Its because you only have the "display-fields".



You need to add display-field="'name'" as well