Get data across site collections
Hello,
Is it possible to use a expression to get data from lists which are stored on other site collections?
The best would be something like the "@Web.GetFirstValueForQuery" just to access other site collections.
Thank you in advance.
-
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 -
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 -
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 -
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 -
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 -
Perfect, working great.
Thanks
0 -
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 -
Try to give read permissions to the web.
0
Please sign in to leave a comment.
Comments
8 comments