Skip to main content

Search

Get data across site collections

Comments

8 comments

  • Markiyan Fostyak

    Hi!

    You are right, you should use 

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

    But make sure to pass list relative URL as the first parameter. Also, it is necessary for the user to have permission for accessing that site collection. 

    0
  • Senad Omicevic

    Thank you, this is working, I have tried it before but with false parameters.

     

    Can I use somehow a variable in the Caml query? I would need to calculate the value before querying the result.

    0
  • Markiyan Fostyak

    You can use variables from Expression Builder. Here is the example: 

    var itemTitle = [[@Web.GetFirstValueForQuery('listRelativeUrl', '<Query><Where><Eq><FieldRef Name="ID" /><Value Type="Text">' + [[@User.Id]] + '</Value></Eq></Where></Query>', 'Title')]];
    return itemTitle;
    0
  • Senad Omicevic

    I am trying to use a calculated variable. Example:

     

    var curMonth = new Date().format("MMMM");
    var result = [[@Web.GetFirstValueForQuery('listRelativeUrl', '<Query><Where><Eq><FieldRef Name="DateCol" /><Value Type="Text">' + curMonth + '</Value></Eq></Where></Query>', 'Title')]];

     

    But this is not working.

    0
  • Markiyan Fostyak

    So, to create query in the way you intend you should use the following approach:

    var itemTitle = [[@Web.GetFirstValueForQuery('listRelativeUrl', '<Query><Where><Eq><FieldRef Name="DateCol" /><Value Type="Text">[[=new Date().format("MMMM")]]</Value></Eq></Where></Query>', 'Title')]];
    return itemTitle;
    0
  • Senad Omicevic

    Perfect, working great.

     

    Thanks

    0
  • Senad Omicevic

    What kind of permissions needs the end user to query from another site collection? 

     

    I gave him the read permissions on the items which hold the data, but it is not working like this.

     

    I have tried to give the read permissions to the list but its neither working.

     

    Thank you

    0
  • Markiyan Fostyak

    Try to give read permissions to the web.

    0

Please sign in to leave a comment.