SOLVED

SharePoint 2016 view filter by subsite name

Brass Contributor

Hi, 

 

I have a list webpart who give project info. 

Title of the project

Description of the project. 

 

This list is create at the site collection level. 

When I fill the new project forms one elements is create in this list. 

A workflow start at the creation and a subsite is create for the new project with a subsite template.

 

I have create another list at the site collection level where I have a workflow who start at the creation too. This one generate user access for the subsite.

 

The goal is to make the work more easy for the user who create the project.

So I have create a wikipage at the site collection level who are an import  of the list use to create the project. I have create this page in SPDesigner 2013 and via designer I have export this page like custom webpart. 

 

Like this, I could add this custom webpart on a wikipage create in the project subsite.

Like this custom webpart is linked with the list at the site collection level, if I add elements on it, the list is updated at the site collection level and vice versa. 

 

That's work great, but this kind of link view doesn't have all list properties Like Connection option. 

So when I generate a new subsite project, my wikipage present all project and all user access. 

 

My goal is to present on each wikipage in each subsite, only the information in link with this project. 

Ex: one line with the name of the project and the description where the name of the project is the name of the subsite. 

So If i create a project name test5, my workflow create a subsite name test5 with the URL 

http://sharepointxxx.com/sites/project/test5

 

I would like than the webpart present only the elements in link with project title test5. 

 

I have find than I could create a view filter with the active user properties. When I check the code of the page I have this query. I would like change "UserID" for Site title. But each test I have make give an error or no result in the list. 

<Query>
<Where>
<Eq>
<FieldRef Name="Author"/>
<Value Type="Integer">
<UserID Type="Integer"/>
</Value>
</Eq>
</Where>
</Query>

 

 Actually in the view forms I use a filter 'create by' with the connected user properties between [ ].

 

 

Any hint is welcome.

 

 

 

 

2 Replies
Ok I have make somes tests.
I have find the Managed Property SiteTitle.
If I use this property in the request of search result webpart.
and I put SiteTitle:test5.
The result is all page in link with the subsite name test5,

But when I try to use this Managed Property SiteTitle like view filter apply on a list, SharePoint do not return any result.
The list stay empty and the search webpart dont give any error.
I have try "SiteTitle" or [SiteTitle], but SharePoint do not reconize this managed property.
best response confirmed by Marc-Etienne_Tremblay (Brass Contributor)
Solution
Hi,
After many time of research I have finally resolve my issue with a content editor and a javascript.
I have find information about javascript on this web site.

https://www.linkedin.com/pulse/sharepoint-list-filtering-javascript-maryam-kaveh
I need to adapt the script for my needs here is a copy of my script.

function myFunction() {
// catch the path and delete "/"
var url = location.pathname.split("/").slice(-3);
var titleprojet;
// loop in the values and copie the first one who are the project title.
var i;
for (i = 0; i < url.length; i++) {

if (i == 0) {
titleprojet = url[i];

}
}

//Switch the title in lowerCase
titleprojet = titleprojet.toLowerCase();

// check if the project title is present in all webparts of the page.
// if the project title if found in the webparts table, show the line of row.
//if not hide the line of row.

if (titleprojet) {


$("#WebPartWPQ2").find("tr.ms-itmhover:not(:Contains("+titleprojet+"))").hide();


$("#WebPartWPQ2").find("tr.ms-itmhover:Contains("+titleprojet+")").show();

$("#scriptWPQ6").find("tr.ms-itmhover:not(:Contains("+titleprojet+"))").hide();


$("#scriptWPQ6").find("tr.ms-itmhover:Contains("+titleprojet+")").show();



} else {


$("#WebPartWPQ2").find("tr.ms-itmhover").show();

$("#scriptWPQ6").find("tr.ms-itmhover").show();
}


}
//Wait than all page elements is loaded before execute myFunction.
// That's give the time to the browser to load the information and show the webparts with the good information.
document.addEventListener("DOMContentLoaded", myFunction);

The result is than SharePoint execute the javascript catch the subsite name and use it like filter on each webparts of the page.
Take care, to change the webpart name in this script for ours and take note, the filtering function work on all columns and row.

So if you want only the line where the title is november or include november.
Besure to modify the view to mask columns where we could find november like the creation date columns.
Because, you could have 2 or more results in the table.

Ex: If you have the table below and you want only the record with the november title.

title | description | create date
november | bla bla bla | 2021 november 4
project 2 | bla bla bla | 2021 november 30

the result after the script process will be than the table will include the 2 records.
Because, the november string will be find in the create date too.

Hope this help.
1 best response

Accepted Solutions
best response confirmed by Marc-Etienne_Tremblay (Brass Contributor)
Solution
Hi,
After many time of research I have finally resolve my issue with a content editor and a javascript.
I have find information about javascript on this web site.

https://www.linkedin.com/pulse/sharepoint-list-filtering-javascript-maryam-kaveh
I need to adapt the script for my needs here is a copy of my script.

function myFunction() {
// catch the path and delete "/"
var url = location.pathname.split("/").slice(-3);
var titleprojet;
// loop in the values and copie the first one who are the project title.
var i;
for (i = 0; i < url.length; i++) {

if (i == 0) {
titleprojet = url[i];

}
}

//Switch the title in lowerCase
titleprojet = titleprojet.toLowerCase();

// check if the project title is present in all webparts of the page.
// if the project title if found in the webparts table, show the line of row.
//if not hide the line of row.

if (titleprojet) {


$("#WebPartWPQ2").find("tr.ms-itmhover:not(:Contains("+titleprojet+"))").hide();


$("#WebPartWPQ2").find("tr.ms-itmhover:Contains("+titleprojet+")").show();

$("#scriptWPQ6").find("tr.ms-itmhover:not(:Contains("+titleprojet+"))").hide();


$("#scriptWPQ6").find("tr.ms-itmhover:Contains("+titleprojet+")").show();



} else {


$("#WebPartWPQ2").find("tr.ms-itmhover").show();

$("#scriptWPQ6").find("tr.ms-itmhover").show();
}


}
//Wait than all page elements is loaded before execute myFunction.
// That's give the time to the browser to load the information and show the webparts with the good information.
document.addEventListener("DOMContentLoaded", myFunction);

The result is than SharePoint execute the javascript catch the subsite name and use it like filter on each webparts of the page.
Take care, to change the webpart name in this script for ours and take note, the filtering function work on all columns and row.

So if you want only the line where the title is november or include november.
Besure to modify the view to mask columns where we could find november like the creation date columns.
Because, you could have 2 or more results in the table.

Ex: If you have the table below and you want only the record with the november title.

title | description | create date
november | bla bla bla | 2021 november 4
project 2 | bla bla bla | 2021 november 30

the result after the script process will be than the table will include the 2 records.
Because, the november string will be find in the create date too.

Hope this help.

View solution in original post