Skip to main content

Search

@Web.GetValuesForQuery

Comments

6 comments

  • Matthias_Walter

    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
  • DavidB3

    Hi Matthias,

     

    Works perfectly, thank you for your help as always.

    0
  • Nicole

    If I try this code I get the message

    Object doesn't support property or method 'getMail'
    0
  • Matthias_Walter

    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
  • Nicole

    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 ID1
     
    Kind regards
    Nicole
    0
  • Matthias_Walter

    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.