none
Access a document library, filtered by column name that is a Lookup table RRS feed

  • Question

  • Hello All,

    I have a need to be able to click a button/link and open a document library that will only display documents where columnName=someValue.

    I can do this via URL with all fields except the one that I actually need.  I believe the problem is that the column I need is a lookup type.  Does anyone have any solution to this?

    I plan to call this from a javascript method.

    Thursday, March 16, 2017 7:50 PM

Answers

  • Hi,

    Please take this demo for a try in your environment to see if it can work properly for you, all you need to do is applying it to the list view page of your list:

    <script type="text/javascript">
    
    _spBodyOnLoadFunctionNames.push("ready");
    
    function ready()
    {
    	console.log("ready");
    
    	document.querySelector("#Btn").onclick = function(){
    		console.log("click");
    		console.log(document.querySelector("#FilterValue").value.trim());
    
    		if("" === document.querySelector("#FilterValue").value.trim())
    		{
    			//set your real URL here
    			location.href = "http://sp/Lists/LS0309/AllItems.aspx";
    		}
    		else
    		{
    			//set your real URL here, as well as the Lookup column name
    			location.href = "http://sp/Lists/LS0309/AllItems.aspx?FilterField1=LKTest&FilterValue1=" + document.querySelector("#FilterValue").value.trim();
    		}
    	};
    }
    
    
    </script>
    <input type="text" id="FilterValue"></input>
    <input type="button" id="Btn" value="run it"></input>

    In my environment, I have a list with a Lookup column “LKTest”:


    Input a value into the textbox:

    Click “run it”, the list view will be filtered like this:

    Best regards,

    Patrick

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Saturday, March 18, 2017 2:10 AM
    Moderator

All replies

  • Hi,

    Please take this demo for a try in your environment to see if it can work properly for you, all you need to do is applying it to the list view page of your list:

    <script type="text/javascript">
    
    _spBodyOnLoadFunctionNames.push("ready");
    
    function ready()
    {
    	console.log("ready");
    
    	document.querySelector("#Btn").onclick = function(){
    		console.log("click");
    		console.log(document.querySelector("#FilterValue").value.trim());
    
    		if("" === document.querySelector("#FilterValue").value.trim())
    		{
    			//set your real URL here
    			location.href = "http://sp/Lists/LS0309/AllItems.aspx";
    		}
    		else
    		{
    			//set your real URL here, as well as the Lookup column name
    			location.href = "http://sp/Lists/LS0309/AllItems.aspx?FilterField1=LKTest&FilterValue1=" + document.querySelector("#FilterValue").value.trim();
    		}
    	};
    }
    
    
    </script>
    <input type="text" id="FilterValue"></input>
    <input type="button" id="Btn" value="run it"></input>

    In my environment, I have a list with a Lookup column “LKTest”:


    Input a value into the textbox:

    Click “run it”, the list view will be filtered like this:

    Best regards,

    Patrick

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Saturday, March 18, 2017 2:10 AM
    Moderator
  • Hi,

    Any update?

    If my reply helps you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best regards,

    Patrick



    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Saturday, March 25, 2017 5:11 AM
    Moderator
  • That was a great answer thank you!  I had to add a bit more processing to the string being passed in, but that functionality is quite useful!
    Tuesday, March 28, 2017 12:34 PM