2

I have a rigged a link to call the NewItem.aspx form in a dialog. When the User clicks 'Save', I would like to return the new item ID in the callback function. How is this achievable?

<a href='javascript:openDialog()'>New Item</a>

function openDialog(test) {

var options = {
        title : "New Item",
        url : "/_layouts/BRP_CustomWelcome/DialogLocation.aspx",
        dialogReturnValueCallback : dialogCallback,
    };

SP.UI.ModalDialog.showModalDialog(options);
}


function dialogCallback(dialogResult, returnValue) {

  if (dialogResult == SP.UI.DialogResult.OK)
  {
      var id = returnValue; //HOW DO I GET THE NEW ID HERE?!
      customJSFunction(id);
  }
}
2
  • You cannot really do it that way. You'll need to wait for Sharepoint to create the new item to know it. So you can redirect the user to another page (the "Source" parameter in the URL) that will query the list with JavaScript to find the biggest ID (= ID just created) and then you can deal with it.
    – AymKdn
    Commented May 19, 2014 at 15:12
  • Gotcha thx..May be easier for me to create a custom add form. Commented May 20, 2014 at 4:09

1 Answer 1

-1

First get the Id of the item, then on click of Save button, close the dialog box and pass Id as the parameter:

//Logic for getting Id
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, Id);
1
  • It say Id is undefined. Where should I put this in my code? Commented May 20, 2014 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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