What am I do wrong with the Related Items filter

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
User avatar
smithme
Posts: 45
Joined: Wed Jul 26, 2017

16 Aug 2017

I can't figure out what I am doing wrong with the Related Items filter but it isn't working the way I expect it to.

My data is arranged as follows:
  • Cemetery
    • Section
      • Lot
        • Space
If I am making the Cemetery form the Related Item control attributes will be set as follows:
List: Sections
View: All Items
Filter by form field
Form field: ID
List Field: Cemetery

When I setup like this it finds nothing.

If I set the Related Item control attributes like this it works:
List: Sections
View: All Items
Filter by form field
Form field: Cemetery
List Field: Cemetery

However, this is matching on the string not on the ID.

I thought it was a problem with how I setup the Cross-site Lookup, but I am using the default, here it is:

List: Cemeteries
Filed: Cemetery

Request items:

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=ID,{LookupField}&$orderby={LookupField} desc&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select=ID,{LookupField}&$orderby={LookupField}&$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "')&$top=10";
}
Item format:

Code: Select all

function(item) {
  return '<span class="csl-option">' + item["{LookupField}"] + '</span>'
}
Should I make the Field = ID and then use the Cemetery field in code like this:

List: Cemeteries
Filed: ID

Request items:

Code: Select all

function (term, page) {
  if (!term || term.length == 0) {
    return "{WebUrl}/_api/web/lists('{ListId}')/items?$select={LookupField},Cemetery&$orderby=Cemetery desc&$top=10";
  }
  return "{WebUrl}/_api/web/lists('{ListId}')/items?$select={LookupField},Cemetery&$orderby={LookupField}&$filter=startswith(Cemetery, '" + encodeURIComponent(term) + "')&$top=10";
}
Item format:

Code: Select all

function(item) {
  return '<span class="csl-option">' + item["Cemetery"] + '</span>'
}
City of Nampa
Idaho
United States of America

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

17 Aug 2017

What you need to know about filtering settings for the Related Items control, that it will filter out all items where a specific field is not equal another field on the Form.

For example, you want to create a basic Children list and add Related Items control. First, you go to Children List and add Lookup column for the Parent List. Lookup field value is always ID! Doesn't matter if it shows title or any other field, its value is always ID. Then you can add Related Items to Edit or Display Form of Parent List and set Filter by Lookup field and ID of the current item. It wouldn't work on the new Form as the item has no ID yet.

In your case I would first create Cemeteries list and add all Cemeteries there. Next, I would create Sections list and tie every section to a Cemetery with a Lookup field. When you open Cemetery Form, you can filter Related Items by Lookup field and ID of the current item. You can continue this pattern down to Lot and individual Spaces, creating Lists and adding Lookups to the Parent.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests