v1.45: Changed the DispForm code to fix an issue with picking up the ID of the selected item. Thanks to Dmitry.
October 29. 2013
v1.44: Fixed a bug where the FieldInternalName and not the DisplayName was used as formlabel.
October 26. 2013
v1.43: Fixed a bug (data is not pulled in) in EditForm. This bug is affecting all browsers, but for IE it kicks in only when the lookup columns contains less than 20 items.
October 17. 2013
v1.42: Changed how the id of the value fields pulled back from the lookup column is generated. This to ensure unique IDs when using this feature on multiple fields. Now the ID is constructed like this:
[FieldInternalName of the Lookup column]_[FieldInternalName of the field pulled in]
Look at the bottom of the article for details.
October 17. 2013
v1.41: Added compatibility with DFFS. To achieve this, I have appended the table to the formbody of the lookup column. This to ensure the information is hidden with the field itself when changing tabs or hiding fields by rules.
This solution lets you pull in additional information from another list based on a lookup column. It works much in the same way as the SP2010 / 2013 lookup column setting “Add a column to show each of these additional fields” found in the list settings > Change column. The difference is that this one works in NewForm and EditForm as well, where the built-in SharePoint feature only works in DispForm.
This image shows NewForm
All the highlighted fields have been pulled in based on the lookup column. Please note that these fields are not stored in the current item, but are shown when viewing the form in NewForm, DispForm or EditForm.
I have updated the code to use spjs-utility.js and thus support newer versions of jQuery and browsers other than IE. The only new feature I have added, is support for displaying the information in DispForm.
I have NOT changed the function call to ensure backwards compatibility with the older solution.
This solution is in fact only tested in SP 2007, but should work for SP2010/2013 as well. Please post any findings below.
Use this code in a CEWP below NewForm, DispForm and EditForm:
<script type="text/javascript" src="/test/English/Lists/PullInfoFromLookup/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="/test/English/Lists/PullInfoFromLookup/spjs-utility.js"></script> <script type="text/javascript" src="/test/English/Lists/PullInfoFromLookup/PullInformationFromConnectedList.js"></script> <script type="text/javascript"> var fields = init_fields_v2(); /* Object containing all arguments for the function * "arrFinAndDispName" is an array on format "FieldInternalName|Display name" from the list the lookup is pulling information from * "ListGuid" is the list Guid or the displayName of the list the lookup is pulling information from * "LookupFIN" is the FieldInternalName of the lookup column. */ var argumentObj = {'arrFinAndDispName':['TextField1|My text field 1', 'TextField2|My text field 2', 'TextField3|My text field 3', 'Responsible|Responsible', 'Hyperlink|Hyperlink', 'RichText|Rich text multi line'], 'ListGuid':'405EC50E-FAF7-4473-8D50-F9E725BEAA9B', 'LookupFIN':'MyLookupColumn'}; init_displayInfo(argumentObj); </script>
Download the code
The code for the file “PullInformationFromConnectedList.js” can be found here, spjs-utility.js is found here, and jQuery here.
How to access the values after they have been pulled in to the table
Each of the TDs with the values have been assigned an ID like this:
MyLookupColumn_TextField1
The green part is the FieldInternalName of the lookup column, and the red part is the FieldInternalName of the field that the info is pulled from.
To get the value from this field, you use a standard jQuery selector like this
var myFieldVal = $("#MyLookupColumn_TextField1").html(); alert(myFieldVal);
Ask if anything is unclear,
Alexander