Have the child item populate the parent

Home Forums vLooup for SharePoint Have the child item populate the parent

Tagged: 

Viewing 3 reply threads
  • Author
    Posts
    • #28540
      Therman
      Participant

        If a user opens a child newForm from the parent and fills out the info, I’d like to capture a value from the child newForm and place it in a field in the parent newForm when the child newForm is saved. Is that possible?

        Specifically, I’m looking to create an icon in the parent so I can indicate in the list view that there is at least one related record. If possible, id also like to make that icon clickable in the list view based off the vlookupid of the parent

        I’ve searched the forums and can’t find the right answer to this. I know I’m not the only one trying to do this. Any help would be greatly appreciated. Thanks!

      • #28561
        Alexander Bautz
        Keymaster

          This example works when you open the child item in a dialog over your parent form, but it also requires that the parent form is saved after the child item is created – to save the value in the counter field.

          Add this to your PARENT form Custom JS (replace YOUR_COUNTER_FIELD with the internal name of the field you want to add the count of children into):

          setInterval(function(){
              if(typeof vLookup_child_count_variable !== "undefined" && vLookup_child_count_variable !== null){
                  var currCount = getFieldValue("YOUR_COUNTER_FIELD");
                  if(currCount === ""){
                      currCount = 0;
                  }
                  var newValue = parseInt(currCount,10) + vLookup_child_count_variable;
                  setFieldValue("YOUR_COUNTER_FIELD", newValue);
                  vLookup_child_count_variable = null;
              }
          },1000);

          Then add this to your CHILD NewForm Custom JS:

          function dffs_PreSaveAction(){
              window.parent.vLookup_child_count_variable = 1;
              return true;
          }

          Let me know how this works out.

          Regarding clicking the field in a view: This is unfortunately not something I can help you with, but if you use classic SharePoint you can use vLookup in a view to show the list of child items: https://spjsblog.com/vlookup-for-sharepoint/vlookup-user-manual/#List_view_setup

          Alexander

          • This reply was modified 4 years, 8 months ago by Alexander Bautz. Reason: fixed code snippet
        • #28594
          Therman
          Participant

            Hey Thanks for the help, Alexander. I tried this, but it didn’t work.
            For some context:
            1 – the field that I’m trying to update is a multiline field
            2 – I open the child newform from the parent editform

            Do any of these factors make a difference?

          • #28596
            Alexander Bautz
            Keymaster

              Do you open it in a dialog, or a full new page (new tab)? – my example only works when opening in a dialog. It is also designed to store the count of child items in a field, and not to update for example a multiline field with a link – to do this the code must be changed.

              Start by adding a new field as “YOUR_COUNTER_FIELD” and see if it works – if it does, you can modify the code to bring back more data.

              Alexander

          Viewing 3 reply threads
          • You must be logged in to reply to this topic.