0

I've set up a list with a Parent Child relationship. When the Parent is edited and save button pressed ther modal dialog opens the child list. When the child is saved the parent is saved also. The problem is I need a way to pass the ID of the parent item to the child to maintain the relationship. I have set up a lookup for the parent id in the child, however i dont think this is necessary as the ID parameter of the Parent item can be passed to the child. The code below does everything except maintain the relationship, could someon assist pls?

    


var setTrue = false;
var target;
var contName;

function PreSaveItem()
{   
    //on first load global varible setTrue is false so we can load the popup. 
    //but when true it will save parent list imitating save click event.
    if ("function"==typeof(PreSaveAction)&& setTrue == false)
    {
              //get the clicked save button so that we can use the id (name) later to save when doing a postback.
        target = event.target || event.srcElement;
        contName = target.name;
              //call the save action to load the child list
        PreSaveAction();
    }
    else
    {
         //do postback with parent save button manually
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(contName, "", true, "", "", false, true));
    }
}

//function that creates child popup to add new item to a child list
function PreSaveAction() 
{  
      var dialogOptions = SP.UI.$create_DialogOptions();
      dialogOptions.url = 'http://sharesite/sites/mysite1/Lists/Time3/NewForm.aspx';
      dialogOptions.width = 750;
      dialogOptions.height = 500; 
      dialogOptions.dialogReturnValueCallback = Function.createDelegate( null, CloseCallback); 
      SP.UI.ModalDialog.showModalDialog(dialogOptions); 
}

//actions (save/cancel) for the child form
function CloseCallback(strReturnValue, target) 
{
    if (strReturnValue === SP.UI.DialogResult.OK) 
    {
       //if we save than set global bool to true
       setTrue = true;
       alert("Thank you for adding time value");
       //call presave item for parent list save
       PreSaveItem();

    }
    if (strReturnValue === SP.UI.DialogResult.cancel) 
    {
        setTrue = false;
        alert( "You clicked cancel!");
    }
 }


  • so you want to put the parent item id into a new custom column in the child when you create a new item? – Ali Jafer Jun 4 '14 at 9:03
  • the question is not clear enough. What is that you weren't able to do? Passing the parent's ID to the child? – MdMazzotti Jun 4 '14 at 9:30
  • Hi I want to passs the Parent ID to a new child custom field. – Raj Chahal Jun 5 '14 at 7:08
  • Hi anyone able to assist on this one? – Raj Chahal Jun 13 '14 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.