09.12.2011 I have updated the solution to v1.1 to let the user chose the icon (or no icon) before the “child” title. The code for the file “ParentChildResources.js”, and the CEWP code for “Parent DispForm” and Child DispForm” has changed. The new “argObj-property” “iconBefore” should be the path to the image to prepend to the “child title”.
I got this request:
I am new to SharePoint and have been struggling with steep learning curve and would really appreciate your help…
This involves putting scripts in NewForm and/or DispForm in three lists. Please follow the steps carefully.
Create the three custom lists used in this example:
This list has the Title field only.
Add one field of type Lookup (single choice) with the name “Parent”. This lookup should target the title field of the "Parent" list.
Add one field of type Lookup (single choice) with the name “Parent”. This lookup should target the title field of the "Child" list.
Download the code from here
The code is presented in individual folders so it’s easy to get the right code in the right form.
Edit the code that goes in the CEWPs to fix the script src attributes in all files, the “childListUrl” in the DispForm code and the various “argObj” variables if your lists or fields has different names. You will have to read trough the code for the CEWPs to find the bits to change.
The file “ParentChildResources.js” does not need any modification.
Upload the code to a shared document library and maintain the folder structure (or rename the files so that you know which file goes where).
Add CEWPs to the list forms and insert the code corresponding with the folder and file name. It is important that you use the content link option to link to the code.
To add a CEWP, go to the list, activate it by clicking in the “list area” to bring up the list tools ribbon. Select the tab “List” and “Form Web Parts”.
You find the content link option like this:
Edit the page and activate the CEWP. In the ribbon toolbar, select “Web Part Tools” and then “Web Part Properties”.
To ensure you get the correct file path, go to the document library, right click the file and select “Copy shortcut”. Paste this URL in the content link field. You might want to edit the URL to make it relative.
Note Add the CEWP below the list form.
This solution uses the Client Object Model introduced in SharePoint 2010 and therefore it will not work on previous SharePoint versions.
To keep this solution clean and simple, the last bits from the request regarding the lookup column, is kept out of this post – it will be emailed to the person requesting this article.
If there is demand for it, i will post it as an appendix to this post later on.
Hope someone can make use of this code.