Multiple lists with 1 lookup

rss

Posted by Hubbaroo - Jan 13 ’15 at 01:18

We are working on creating a library template that uses the cross site lookup to 1 list. In the end we need to create items in the child list, each item related to the parent list, not a single parent item. The required functionility being the cross site lookup only shows items created from that parent list. I'm struggling with the best logic.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 2 months 8 days
    #1 by Dmitry Kozlov Jan 14 ’15 at 06:43

    Hi,

    You can create a flag field (Yes/No) that indicates whether an item was created from the parent list and prepopulate it with the appropriate value via JavaScript in the New form. Next, you can modify 'Request items' template of the lookup field to request items filtered by the flag. Does it make sense?

  • Hubbaroo
    Member
    Member for: 8 years 2 months 9 days
    #2 by Hubbaroo Jan 14 ’15 at 10:11

    [#1]: Almost. After we create several lists from the template we need to filter the lookup based on what list is doing the lookup. So when the item is created in the lookup list it needs to have a column to identify what list created it. When the parent list creates the child record from the "Add new item" link on the lookup what can we get to identify the parent list? In this usage we have a many to one, not a one to many.

     

    Thanks again.

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 2 months 8 days
    #3 by Dmitry Kozlov Jan 15 ’15 at 03:33

    [#2]: Hi,

    You can get Id of the parent list from the child form via JavaScript following way:
    window.top._spPageContextInfo.pageListId

    Next, save it into a hidden field and filter the Cross-site Lookup by this field:

    function (term, page) {
      if (!term || term.length == 0) {
        return "{WebUrl}/_api/web/lists('{ListId}')/items?" + 
    		"$select=Id,{LookupField}&" +
    		"$orderby=Created desc&" +
    		"$top=10&" +
    		"$filter=ParentListId eq '" + _spPageContextInfo.pageListId + "'";
      }
      
      return "{WebUrl}/_api/web/lists('{ListId}')/items?" +
    	"$select=Id,{LookupField}&" +
    	"$orderby={LookupField}&" +
    	"$filter=startswith({LookupField}, '" + encodeURIComponent(term) + "') and ParentListId eq '" + _spPageContextInfo.pageListId + "'&" +
    	"$top=10";
    }
    
  • Hubbaroo
    Member
    Member for: 8 years 2 months 9 days
    #4 by Hubbaroo Jan 15 ’15 at 10:18

    [#3]: This is sweet and will work perfect!!! Better than my getting the url and splitting out the list name to filter on. Thanks again!!!

Displaying 1 to 4 of 4 messages