Skip to main content

Search

Get Values from another list

Comments

1 comment

  • m.fostyak

    Hello Sandra

    You are right, to retrieve data from a list you should use

    [[@Web.GetFirstValueForQuery('ListName or relative Url', 'Caml query', 'FieldName')]]

    Also you have to specify correct parameters for this method:

    1. 'ListName or relative Url' - name of the list you want to get item from.
    2. 'Caml query' - query to filter all items in the list. See examples: here.
    3. 'FieldName' - internal name of the field, you want to retrieve.

     

    An example:

    [[@Web.GetFirstValueForQuery('Customers', '<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Text">2</Value></Eq></Where></Query>','Title')]];

    This will return only the value of field "Title" of list "Customers" with ID equals 2.

     

    Also you can use

    [[@Web.QueryList('ListName or relative Url', 'Caml query', MaxRowNumber, 'View Fields', 'Viewattributes')]]

    Parameters for this method:

    1. 'ListName or relative Url' - name of the list you want to get item from.
    2. 'Caml query' - query to filter all items in the list. See examples: here.
    3. MaxRowNumber - number of rows to get.
    4. 'View Fields' - comma separated names of the fields you want to get.
    5. 'Viewattributes' - attributes, in your case can be left empty.

    I have added a simple example: 

    var x = [[@Web.QueryList('Customers', '<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Text">2</Value></Eq></Where></Query>', 100, 'ID, Title, Address', '')]];
    var item = x[0].get_fieldValues();
    return item["Title"];

    This query will get the item with ID equals 2 from list "Customers". And sets field value as value of the "Title" of this item. But you can use item['Address'] or item['ID'] to get values of other fields specified in the 4th parameter.

     

    So for your case you can use GetFirstValueForQuery with corresponding parameters.

     

    Best Regards

    Markiyan Fostyak

    0

Please sign in to leave a comment.