Related Items filtered by Cross-Site-Lookup-Field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Mapleleaf
Posts: 29
Joined: Tue Oct 25, 2016

29 Jul 2019

Hello,

I made a form with a related item on it. The field, which sets the filter for the related-item is a cross-site-lookup-field. Unfortunatly when I use data-source-filtering the filter is set on the ID of the lookup-field and not on the value. The code which is visible under "view" is pasted below (Code 1). The filter-field and kookup-field is snr.

In Code 2 I set the filter in the code on static-value 99999. This works and filters the related-item. Only entries with snr = 99999 are shown.

Is there a possibility to filter the related-items by the lookup-value and not by thd ID?

Thank you for your help.

Code 1:

<View>
<ViewFields>
<FieldRef Name="DocIcon" />
<FieldRef Name="LinkFilename" />
<FieldRef Name="Title" />
<FieldRef Name="snr" />
</ViewFields>
<ViewData />
<Query>
<GroupBy Collapse="TRUE" GroupLimit="30">
<FieldRef Name="snr" />
</GroupBy>
<OrderBy>
<FieldRef Name="FileLeafRef" />
</OrderBy>
</Query>
<Aggregations Value="Off" />
<Mobile MobileItemLimit="3" MobileSimpleViewField="LinkFilename" />
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<JSLink>clienttemplates.js</JSLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noitemsinview_doclibrary)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noitemsinview_doclibrary_howto2)" />
</ParameterBindings>
</View>


Code 2:

<View>
<ViewFields>
<FieldRef Name="DocIcon" />
<FieldRef Name="LinkFilename" />
<FieldRef Name="Title" />
<FieldRef Name="snr" />
</ViewFields>
<ViewData />
<Query>
<GroupBy Collapse="TRUE" GroupLimit="30">
<FieldRef Name="snr" />
</GroupBy>
<OrderBy>
<FieldRef Name="FileLeafRef" />
</OrderBy>
<Where>
<Eq>
<FieldRef Name="snr" />
<Value Type="Text">99999</Value>
</Eq>

</Where>
</Query>
<Aggregations Value="Off" />
<Mobile MobileItemLimit="3" MobileSimpleViewField="LinkFilename" />
<Toolbar Type="Standard" />
<XslLink Default="TRUE">main.xsl</XslLink>
<JSLink>clienttemplates.js</JSLink>
<RowLimit Paged="TRUE">30</RowLimit>
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noitemsinview_doclibrary)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noitemsinview_doclibrary_howto2)" />
</ParameterBindings>
</View>

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

31 Jul 2019

Hello Mapleleaf!

You can filter related items view dynamically based on the lookup value, please have a look at this article to get the step by step instructions.

Please follow the setup steps from the article. The code for your fields will be as below.

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('snr').change(setHash);
 
//this is the actual function that filters the list
function setHash(){
//get value
var value =  fd.field('snr').control('getSelectedText');
if (value == "(None)") {
value = "";
}
 
value =  encodeURIComponent(escape(value)).replace(/\-/g, "%252D");

window.location.hash = "InplviewHash" + $(".related-issues [webpartid]").attr("webpartid") + '=FilterField=snr-FilterValue=' + value;
}
Is that what you want to develop?

Mapleleaf
Posts: 29
Joined: Tue Oct 25, 2016

31 Jul 2019

Yes it works. Great. Thank you.

I had to change
var value = fd.field('snr').control('getSelectedText');
into
var value = fd.field('snr').control('data')['snr'];
to get the right value.

And final
};
in the function is missing in your code.

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

01 Aug 2019

Mapleleaf,

Sorry, my bad!

Thank you for noticing. Glad I could give you a hint on this.

Mapleleaf
Posts: 29
Joined: Tue Oct 25, 2016

27 Aug 2019

Hi,
is it possible to filter two related-items in one form?

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

28 Aug 2019

Hello Mapleleaf,

If you have two 'Related items' control in the form, you can filter them both.

Follow the same steps for filtering the second control, just rename the function, for example, setHash1()

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests