- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 06:21 AM
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',
}
];
})();
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 07:45 AM
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'
}
];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 07:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 07:41 AM
Hello Thanks for the reply,
Can you please tell me what changes needs to be done to make it work ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 07:45 AM
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'
}
];
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2022 10:18 PM
Thanks Chris It worked