Filter List or Library Control By Parent itemID

Hello, Plumsail Community.

I am just getting into Tab use and wonder if anyone has experience with how to filter a Child List to only show items created from within a specific Parent List. @vhancock, you posted a beautiful application full of Tabs with some List of Library Controls - perhaps you have wisdom here too?

Example: A Parent List item field (ID) is shown above this Child List or Library Control just for demonstration purposes. I'd like to create a relationship with each comment and filter the Child List to only show comments that originated from its Parent List. Suppose other users are editing other items in the Parent List and they are submitting comments to the same Child List. I do not want any comment from other items to be shown here.
FilterListLibCtl

Key Points

  • User receives an assignment to review an item in the parent list
  • User opens (edits) item in EDIT view
  • Within the parent, is a List or Library Control used to leave comments about the specific item in Parent List; others will review this same item later, read the comments, and add more comments
  • I have already applied JS to populate the "Commentor" field with the currently logged-in user by placing the value in a standard text field

Filter by Current User

fd.spRendered(function() {

	var currentUserName = _spPageContextInfo.userDisplayName;
    	fd.field('TextField').value = currentUserName;
    });


fd.spRendered(function() {
    //prepopulating fields of a new List or Library record with the values from the parent form
    fd.control('Comments').$on('edit', function(editData) {
        //var currentUserName = _spPageContextInfo.userDisplayName; is used in a previous block to set the value of 'TextField' to be available for use here
        //Check that this is a new record
        if (editData.formType === 'New') {
            //Prepopulating AssignedTo field
            editData.field('Commentor').ready(function() {
                editData.field('Commentor').value = fd.field('TextField').value;
            });
        }
    });
});

Problem

  • I only want comments that relate to this item and no other (I vaguely feel that a itemID, ctx, row are involved but I don't know how or where to apply it)
  • The Child List will house comments from hundreds of Parent List items

Considering

  • Maybe I can use the same approach as with the currentUserName and populate another field in the Child List item with the itemID of the Parent List item. Hmmm, thought of this as I typed but willing to learn of more elegant approaches.
1 Like

Yes, that worked, to create a lookup field in the Child List, then filter against it.

fd.spRendered(function() {
    pnp.sp.web.lists.getByTitle("ParentListName").items.select("Title,ID").filter("Title eq 'ParentListName'").getAll().then(function(allItems){

  console.log(allItems);
});


	var currentItemID = itemID;
    	fd.field('ParentitemID').value = currentItemID;
    });
    

fd.spRendered(function() {
    //prepopulating lookup field of a new List or Library record with the values from the parent form
    fd.control('ListorLibraryControlName').$on('edit', function(editData) {
        //var currentItemID = itemID; is used in a previous block to set the value of 'ParentitemID' to be available for use here
        //Check that this is a new record
        if (editData.formType === 'New') {
            //Prepopulating ParentListeitemID field
            editData.field('ParentListeitemID').ready(function() {
                editData.field('ParentListeitemID').value = fd.control('ParentitemID').value;
            });
        }
    });
});

In each item now only reveals comments that match the Parent List itemID.

1 Like