@Web.GetValuesForQuery
I have the following function code which is in the initial value part of a field to return the first person from a library to invite to a meeting.
return ([[@Web.GetFirstValueForQuery('Attendees', '<Query><Where><IsNotNull><FieldRef Name="ID" /></IsNotNull></Where></Query>', 'Attendee')]]).get_email();
This works ok and the first person is inserted into the field, however I need to return more than one person and when i try to use @WebGetValuesForQuery, i get the following error.
Failed eval expression: Error occurred on evaluating expression "{ return ([[@Web.GetValuesForQuery('Attendees', '', 'Attendee')]]).get_email(); }"TypeError: arguments[0].get_email is not a function
Hope this is clear.
Thank you.
-
Hi David Beckinsale,
using the GetValuesForQuery function will return an array of objects. Therefore you would need to loop through them like this:
var attendees = "";
var attendeesObjs = [[@Web.GetValuesForQuery('Attendees', '<Where></Where>', 'Attendee')]];
attendeesObjs.forEach(function (attendee){
if(attendee.get_email()!=""){
attendees += attendee.get_email()+";";
}
});
return attendees;Kind regards
Matthias
0 -
Hi Matthias,
Works perfectly, thank you for your help as always.
0 -
If I try this code I get the message
Object doesn't support property or method 'getMail'0 -
Nicole which code are you trying? the one from david or from me? Is your person field configured as single or multi person field?
0 -
Hi Matthias_Walter
I am trying your code above. I got the following result
Object doesn't support property or method 'get_email'My issue is:I have a list "Attendees" with the field type single Person or group (no multiple entries in a field).In my list "Meeting" I want to get the name of the attendee with for example ID1Kind regardsNicole0 -
Hi Nicole,
for single user fields you can use our GetFirstValueForQuery function, which returns a user object that has again 3 functions to get Name, Email or ID:
(just replace and define your own CAML query that fits your needs)
For the Name use
[[@Web.GetFirstValueForQuery([[@Web.ServerRelativeUrl]]+'/Lists/Attendees', '<Where>your caml query</Where>', 'Attendee')]].get_lookupValue()
or for the Email use
[[@Web.GetFirstValueForQuery([[@Web.ServerRelativeUrl]]+'/Lists/Attendees', '<Where>your caml query</Where>', 'Attendee')]].get_email()
or for the ID use
[[@Web.GetFirstValueForQuery([[@Web.ServerRelativeUrl]]+'/Lists/Attendees', '<Where>your caml query</Where>', 'Attendee')]].get_lookupId()
0
Please sign in to leave a comment.
Comments
6 comments