1

I have to call a sharepoint list form and pass its data to the current page. I created a modal and function to collect the data with the below code

function openDialogAndReceiveData() {
        var options = {
            url: 'https://domain.sharepoint.com/sites/ProjectSites/test/Lists/Additional%20Information/NewForm.aspx',
            title: 'test',
            dialogReturnValueCallback: onPopUpCloseCallBackWithData
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }

    function onPopUpCloseCallBackWithData(result, returnValue) {
        if (result == SP.UI.DialogResult.OK) {
            SP.UI.Status.removeAllStatus(true);
            var sId = SP.UI.Status.addStatus("Data successfully populated to text boxes from Pop-up");
            SP.UI.Status.setStatusPriColor(sId, 'green');
            alert(returnValue[0]);
            //alert(returnValue[1]);
        }
        else if (result == SP.UI.DialogResult.cancel) {
            SP.UI.Status.removeAllStatus(true);
            var sId = SP.UI.Status.addStatus("You have cancelled the Operation !!!");
            SP.UI.Status.setStatusPriColor(sId, 'yellow');
        }
    }

on the form i have added the below

 <input id="btnClientOk2" type="button" value="Client Side OK and pass Value to Base Page" onclick="closePopupAndPassData()" />
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">

     function closePopupAndPassData() {
         var popData = [];
         popData[0] =$("input[title='Title']").val();
         popData[1] = "test2";
         SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, popData);
     }
 </script>
0

Add below script in PopUp Page and call it on submit click:

  function closePopupAndPassData() {
     var popData = [];
     popData[0] = document.getElementById('<%= txtPopData1.ClientID %>').value;
     popData[1] = document.getElementById('<%= txtPopData2.ClientID %>').value;
     SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, popData);
 }

This will close the popup and call your onPopUpCloseCallBackWithData method.

  • is txtPopData1 and txtPopData2 names of the textboxs from the from the oob form? – Rinu Dec 6 '17 at 5:10
  • Yes these are the form fields. – Deepmala Dec 6 '17 at 6:30
  • can you share the full code i am not able to do as advised – Rinu Dec 6 '17 at 7:32
  • i have updated the question with the code you mentioned but it throws an error on alert(popData[0]); – Rinu Dec 6 '17 at 8:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.