Related Item filtered by 2 List Fields

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
TonyDuke
Posts: 71
Joined: Mon Sep 11, 2017

29 Jun 2018

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
Capture.PNG (14.09 KiB) Viewed 2088 times
Thanks

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

02 Jul 2018

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;
}
Cheers

Jaydius
Posts: 43
Joined: Thu Nov 12, 2015

17 Aug 2018

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,'&amp;ID='),'&amp;')"/>
<xsl:comment>
<xsl:value-of select="ddwrt:GenFireConnection(concat('*', '@Personnel=', ddwrt:ConnEncode(string($LookupValue))), '')" />
</xsl:comment>

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

17 Aug 2018

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests