Multiple lists with 1 lookup
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
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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?
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?
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.
Thanks again.
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
You can get Id of the parent list from the child form via JavaScript following way:
Next, save it into a hidden field and filter the Cross-site Lookup by this field:
You can get Id of the parent list from the child form via JavaScript following way:
Code: Select all
window.top._spPageContextInfo.pageListId
Code: Select all
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";
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests