Few days ago, I wrote a post about how to Create a new lookup field using JSOM in Office 365. Continuing with the same scenario, we have two related libraries: Documents and Pages, and the requirement is to see for every page one list of related documents.
If you look at the picture, this is how lookup field is filled in the Documents library.
And here is the code we need to use using a
Script WebPart or
Content Editor WebPart inside the Pages Library documents or pages.
Note: This is important to note that this code is using some context variables related to current page id and this code is only working if that is inside a page. For example, if we have a page like that:
Note: We can try / debug our code using F12 (Developer Tools in Chrome or IE).
Here is the code to achieve the image results: