Page 1 of 1
Related Item filtered by 2 List Fields
Posted: 29 Jun 2018
by TonyDuke
Good Day,
I have a Related Item Control on a Display Form (no dynamic requirement needed), for a list called Companies, with a field on the display form called Company Name, I want the related item control to filter and show items where the Form Field - Company Name (Company_x0020_Name) matches either List Field - Company Name (Company_x0020_Name) or List Field - Correspondence Company Name (Correspondence_x0020_Company_x0020_Name) in a List called Quotations, is there a simple way to do this, the List Fields are both Lookups to the Company Name field in the Companies List.
So in effect adding an additional List Field to the below: -
- Capture.PNG (14.09 KiB) Viewed 2090 times
Thanks
Re: Related Item filtered by 2 List Fields
Posted: 02 Jul 2018
by Nikita Kurguzov
Dear Tony,
If you need filtering by two fields, the easiest way would be to configure it through the hash, even if you don't need dynamic filtering. Just follow
this instruction and when you'll construct the hash, use code kind of like this:
Code: Select all
//first filter on page load
setHash();
//and attach an on-change handler that will call the filtering function wherever the value of the field changes
fd.field('Department').change(setHash);
fd.field('Department2').change(setHash);
//this is the actual function that filters the list
function setHash(){
//get value
var value = fd.field('Department').value();
if (!value) {
value = "";
}
var value2 = fd.field('Department2').value();
if (!value2) {
value2 = "";
}
value = encodeURIComponent(escape(value)).replace(/\-/g, "%252D");
value2 = encodeURIComponent(escape(value2)).replace(/\-/g, "%252D");
//set the URL’s hash value. An explanation on this is at the end of the article.
window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + "=FilterField1=Department-FilterValue1=" + value + "-FilterField2=Department2-FilterValue2=" + value2;
}
Re: Related Item filtered by 2 List Fields
Posted: 17 Aug 2018
by Jaydius
Is it possible to use list fields that have multiple values? The following code works for me for a standard filter on related items, but using the SetHash code for 2 list fields, it doesn't help:
Code: Select all
<xsl:variable name="LookupValue" select="substring-before(substring-after(@Personnel,'&ID='),'&')"/>
<xsl:comment>
<xsl:value-of select="ddwrt:GenFireConnection(concat('*', '@Personnel=', ddwrt:ConnEncode(string($LookupValue))), '')" />
</xsl:comment>
Re: Related Item filtered by 2 List Fields
Posted: 17 Aug 2018
by Dmitry Kozlov
Hi!
Yes, you can filter a list by multiple columns via hash. Just try to filter a list view manually by using column headers and check the URL. Try to combine the same URL from your code.