0

I have two SP lists, lstParent and lstChild.

lstParent has a unique field called ID and is related to lstChild by a field called ParentID.

Both lists are properly displayed in a web-part page and they are synchronised together well; i.e. lstChild can shows only the related items of lstParent well.

Now my question:

When I add a new item in lstChild, is it possible to make the default value of the ParentID field to the current lookup value of the ID field of lstParent? For example, if lstChild currently displays the related records for ParentID 11, then when a new record should have this field default to 11. Is there any way to do so? Please advise.

Norman

  • This is not possible using SharePoint out of the box capabilities. Are you using classic experience (as you mentioned web part page)? – Ganesh Sanap Sep 29 '22 at 05:25
  • Yes, as the classic experience allows me to select the type of page (web part, wiki, etc)... I don't know how to create the same effect in "new experience" page. By the way, thanks for telling me that it is not possible to do so. – HandsomePig Sep 30 '22 at 07:52
  • When you select any item in lstParent, does it add item ID from lstParent list to browser URL? As you are using classic experience, if it adds item ID in browser or somewhere in page context, you can read ID using JavaScript and put it in child list form on form load. – Ganesh Sanap Sep 30 '22 at 08:01
  • @GaneshSanap Yes, I can see the ID of the selected item of lstParent in the URL. For the Javascript, though I could find the code for extracting required segments from the URL here: https://stackoverflow.com/questions/35679896/javascript-get-url-segment-and-parameter I don't know how to put this code into context. Would you mind giving me further direction on this (Actually I don't know Javascript (but I do know other programming languages) and I don't know much about SharePoint). – HandsomePig Oct 03 '22 at 06:41

1 Answers1

0

You can read selected item ID of parent list from URL using code like below:

const urlParams = new URLSearchParams(window.location.search);
const selectedId = urlParams.get('SelectedID');

Note: URLSearchParams is not supported on all browsers, for other ways to read query string parameters from URL, check this: How can I get query string values in JavaScript?


You need to get the selected item ID from new form page of child list, then you can use this ID to auto-populate value in your lookup column in child list form.

Ganesh Sanap
  • 1,386
  • 1
  • 8
  • 18