- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 08:22 AM
I have a contact page in the portal and I am appending each departments contact with multiple values into an array . If there is one contact it works fine. But if there are multiples then I'm getting an error message
Server Side
data.departments = {
'HR': [
]
Talent = {
'name': gr.u_talent.first_name,
'phone': gr.u_talent.phone.toString(),
'email': gr.u_talent.email.toString()
}
data.departments.HR.push(Talent);
If there is one person listed under talent and this was not a list field it works fine. But now that that u_talent is a list field it is throwing me an error . how can i parse the different users in this list to display them in the portal via html
HTML
<div ng-repeat="(label,departments) in data.departments">
<div class="parent">
<div ng-repeat="contact in departments">
<div>{{contact.name}}</div>
<div>{{contact.email}}</div>
<div>{{contact.phone}}</div>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 08:56 AM
Get the value of the list field to get a list of sys_ids. I don't know off the top of my head if that ends up being a string or array so you may need to use .split() to turn it into an array. Once you have that list array, you can loop through it to generate the data.departments.HR object array. It would look something like this:
//Server Side
data.departments={
'HR': []
};
var gr = new GlideRecord('table');
gr.addQuery('table','value');
gr.query();
while(gr.next()){
var userList = gr.getValue('u_talent').split(',');
for(var i = 0; i < userList.length(); i++){
var gr2 = new GlideRecord('sys_user');
gr2.get(userList[i]);
Talent = {
'name': gr2.first_name,
'phone': gr2.phone.toString(),
'email': gr2.email.toString()
}
data.departments.HR.push(Talent);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 08:56 AM
Get the value of the list field to get a list of sys_ids. I don't know off the top of my head if that ends up being a string or array so you may need to use .split() to turn it into an array. Once you have that list array, you can loop through it to generate the data.departments.HR object array. It would look something like this:
//Server Side
data.departments={
'HR': []
};
var gr = new GlideRecord('table');
gr.addQuery('table','value');
gr.query();
while(gr.next()){
var userList = gr.getValue('u_talent').split(',');
for(var i = 0; i < userList.length(); i++){
var gr2 = new GlideRecord('sys_user');
gr2.get(userList[i]);
Talent = {
'name': gr2.first_name,
'phone': gr2.phone.toString(),
'email': gr2.email.toString()
}
data.departments.HR.push(Talent);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2022 07:16 PM
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 01:56 PM
do you know how i can turn this into a function to accept a value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 02:15 PM
The answer would be dependent on where the value is coming from. There are some great examples here: