Forum Discussion

Marc-Etienne_Tremblay's avatar
Marc-Etienne_Tremblay
Brass Contributor
Mar 23, 2021
Solved

Use crawl properties like filter in a URL or a javascript, it's possible ?

Hi,   It's  possible to use Mapped Crawled Properties like list filter in the web site URL ?  Actually, I make test to force filter on somes lists columns in my page.  To have the right url struct...
  • 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 found in the create date too.

    Hope this help.