0

In a SharePoint Online environment, I have a set of pages, each with a single page filter to drive 4 list/library web part views. I want to retrieve the value of that page filter and use it in some Content Editor Web Parts on the page.

The page filter is the value of a Business Function, with some options being Finance, Marketing, HR. The library views include Meeting Documents, Key Documents, and others. So one page would be Meeting Docs, Key Docs, etc., for Marketing. Another page would be Meeting Docs, Key Docs, etc., for HR. Above each list/library view, I want to have nicely-formatted headings like "Meeting Documents for Finance" and "Key Documents for Finance."

I have ~20 of these pages and want to keep maintenance to a minimum, which is why I'd like to retrieve the page filter and have it dynamically populate the headings.

I've tried following the example provided in this post: How to get value of List Filter web part in Javascript?, but do not have enough knowledge to put it all together.

Here is what I have in a script editor web part so far:

<script src="/sites/company/Scripts/jquery-1.6.4.min.js"></script>
<script src="/sites/company/Scripts/jquery.SPServices-0.7.1a.min.js"></script>

<script>

function getListFilterValueFromContextInfo(){

  var filterFields = ctx.overrideFilterQstring.split('&');   
  var filterFunction = filterFields[1].split('=')[1];
  return filterFunction;
}


ExecuteOrDelayUntilScriptLoaded( getListFilterValueFromContextInfo, "sp.js" );
var functionName=filterFunction;
alert(functionName);

</script>

I know I have a problem with global/local variables, but I can only ever seem to get the script to post an "alert" from within the function, or document.write outside the function, but without a value.

Thanks in advance for any direction!

  • Can you confirm the headings that you like to have nicely formatted on the page exist in the url? If yes, could you also post the sample urls in your question? – Ahmad Zia Jan 1 '18 at 8:29
  • The headings do not exist in the URL. They are just Content Editor Web Parts. I want to update the text within the CEWP with the value found in the page filter. Hope that makes sense. – Laura Calaway Jan 1 '18 at 18:15
  • To put a finer point on it, I'm not passing the value in via URL or as a query string. I have a column in the page library called "Function," and I use the OOTB Page Field Filter to compare the value in that column to the "Function" column in the document library to filter the views accordingly. The URL of my page is simply: company.sharepoint.com/sites/DCGlobalDocuments/Pages/… – Laura Calaway Jan 1 '18 at 18:26
  • Please open the page in Google chrome and go to console and paste this ctx.overrideFilterQstring; to make sure the required information (in your case its heading) are there. Can you post that in your answer? – Ahmad Zia Jan 2 '18 at 8:01
0

I was able to find an answer through other sources. Ultimately I just needed to include a span tag to get the value onto the page:

function getListFilterValueFromContextInfo(){

    var filterFields = ctx.overrideFilterQstring.split('&'); 
    var filterFunction = filterFields[1].split('=')[1];
    document.getElementById("myspan").innerHTML= "Meeting Documents for " + 
    filterFunction;
}

ExecuteOrDelayUntilScriptLoaded( getListFilterValueFromContextInfo, "sp.js" 
);

</script>
<span id="myspan"> </span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.