Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set multiple values to sn-record-picker ?

Mahesh23
Mega Sage

Hello community,

Can someone tell me what's wrong with with below code?

Expected output :


Actual output :


HTML:

<div ng-repeat="item in c.data.list">
  <label for="requested-for">${Requested For}</label>
  <sn-record-picker 
     id="requested-for" field="c.requestedFor" 
     table="'sys_user'" 
     display-field="'name'" 
     value-field="'sys_id'" 
     search-fields="'name'" 
     page-size="100" >
  </sn-record-picker>
</div>

Client Script:

api.controller = function() {
    /* widget controller */
    var c = this;

	
    for (var t in c.data.list) {
     myFun(c.data.list[t].name, c.data.list[t].sysId)
    }
	function myFun(requestedForName, requestedForSysId){
		 c.requestedFor = {
            displayValue: requestedForName,
            value: requestedForSysId,
            name: 'requestedFor'
        };
	}
};

Server Script:

(function() {
	/* populate the 'data' object */
	/* e.g., data.table = $sp.getValue('table'); */

	data.list = [
		{
			'name' : 'Abel Tuter',
			'sysId' : '62826bf03710200044e0bfc8bcbe5df1',
		},
		{
			'name' : 'Aileen Mottern',
			'sysId' : '71826bf03710200044e0bfc8bcbe5d3b',
		}

	];

})();

 

1 ACCEPTED SOLUTION

That's your job. I'm just helping troubleshoot 🙂

You probably want to generate requestedFor in the server script and then use the "item" you're looping over in your ng-repeat like:

field="item"

server script:

	data.list = [
		{
			'displayValue' : 'Abel Tuter',
			'value' : '62826bf03710200044e0bfc8bcbe5df1',
			'name': 'requestedFor'
		},
		{
			'displayValue' : 'Aileen Mottern',
			'value' : '71826bf03710200044e0bfc8bcbe5d3b',
			'name': 'requestedFor'
		}

	];

View solution in original post

4 REPLIES 4

_ChrisHelming
Tera Guru

At the very least, you shouldn't have multiple HTML elements with the same ID:
id="requested-for"

second, your client script is overwriting itself:

    for (var t in c.data.list) {
     myFun(c.data.list[t].name, c.data.list[t].sysId)
    }
	function myFun(requestedForName, requestedForSysId){
		 c.requestedFor = {
            displayValue: requestedForName,
            value: requestedForSysId,
            name: 'requestedFor'
        };
	}

you're going to end up with c.requestedFor only being the second/latest value.

Hello Thanks for the reply,

Can you please tell me what changes needs to be done to make it work ?

That's your job. I'm just helping troubleshoot 🙂

You probably want to generate requestedFor in the server script and then use the "item" you're looping over in your ng-repeat like:

field="item"

server script:

	data.list = [
		{
			'displayValue' : 'Abel Tuter',
			'value' : '62826bf03710200044e0bfc8bcbe5df1',
			'name': 'requestedFor'
		},
		{
			'displayValue' : 'Aileen Mottern',
			'value' : '71826bf03710200044e0bfc8bcbe5d3b',
			'name': 'requestedFor'
		}

	];

Thanks Chris It worked