0

So I have been trying to write this code for SP 2010 to first bring up the newDocSet.aspx form for the user to create a custom Doc Set and then directly afterwards copy files into the Doc Set using JSOM. Here's how I have it..

function Opendialog()
{
    var options = SP.UI.$create_DialogOptions();
    options.title = "Create New Mod"
    options.resizable = 1;
    options.scroll = 1;
    options.url = serverUrl+"/subsites/_layout/NewDocSet.aspx?...extranious_data_here";
    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
    SP.UI.ModalDialog.showModalDialog(options);
} 

// Dialog close event capture function
function CloseCallback(strReturnValue, result)
{
    if (strReturnValue === SP.UI.DialogResult.OK) // Perform action on Ok.
    {
        alert("It worked!");
        //get newly created doc set name some how??
        //copy files into doc set using the new name??
    }

    if (strReturnValue === SP.UI.DialogResult.cancel) // Perform action on Cancel.
    {
        alert( "User clicked Cancel!");
    }
}

And I already tested and verified my copyTo() function into a manually created docset. But the issue is the line "alert("It worked!");" never gets called. The page redirects to inside the new document set before any code can run! The "User clicked Cancel!" alert does pop up so I know the CloseCallback function is at least working.

So technically I have two questions. The first of which is how can I ensure that all my code is finished before the page redirects. If there is a way to just completely disable the redirect that would be fine. And the second is, is there a way to easily get the name of the document set that the user just created so I can use it for my copyTo()?? I was trying examine that "result" parameter in CloseCallback but I cant print anything for testing because the page redirects!

Thank you in advance for any assistance you can provide! It is much appreciated!

3
  • Oh and if you would like to see my copyTo() function I can post that but I already verified it worked independently of this code so I left it out to save space.
    – Riggy
    Aug 12, 2015 at 13:36
  • Does your NewDocSet.aspx use the SharePoint:SaveButton control or a custom button? It seems to me that your NewDocSet might be sending a refresh and skipping the callback on success Aug 12, 2015 at 17:24
  • Yea, everything is default. I haven't touched the .aspx form that is generated automatically by SharePoint.
    – Riggy
    Aug 12, 2015 at 20:42

2 Answers 2

1

I don't think you can prevent the redirect as you have little control over the layouts page's behavior. Here's a workaround you can try:

Use the Source parameter and force the NewDocSet.aspx page to redirect to an intermediate page, a page that you've written, and execute your code there.

function Opendialog() {
    var options = SP.UI.$create_DialogOptions();
    options.title = "Create New Mod"
    options.resizable = 1;
    options.scroll = 1;
    options.url = serverUrl + "/subsites/_layout/NewDocSet.aspx?<other params>&Source=/SitePages/DocSetRedirect.aspx";        
    SP.UI.ModalDialog.showModalDialog(options);
}

http://sympmarc.com/2009/10/20/passing-a-source-parameter-on-the-query-string-with-multiple-other-parameters/

The next problem you'll need to face is identifying the correct document set. A simple REST or JSOM query can do this for you. Just query for document sets created by the current user, order by created date descending, rowlimit of one. I'll leave the implementation details up to you :) . Once the code finishes you can then redirect the user to the destination of your choice.

It's not the most elegant solution I've ever devised. Your users will see a bit of a lag as they redirect once, wait for the code to execute, then redirect a second time. But it's easy to build and it gets the job done. Maybe you can display a little "Working on it" message to prepare the users for their next upgrade.

1
  • I had some variables saved in the original page that I needed to use in my "post dialog" code. So I would have to pass all those as parameters to the intermediate page as well. It's just a pain. I ended up doing something similar though so I gave you best answer. I just put a button up in the Doc Set header that runs my copyTo and parsed variables out of the URL.. Very sloppy but whatever..
    – Riggy
    Aug 13, 2015 at 13:42
2

As Long as you just include the newDocSetPage in a Modaldialog, you won´t get a DialogResult.cancel, just because the newDocSet.aspx doesn´t know about your modaldialog and therefore won´t Close it using SP.UI.DialogResult.OK.

You will have to do this by yourself. Either there is is possible using the JavaScript-Client object model, or you will have to create your own page doing your work and that is able to Close the Dialog.

3
  • I'm not sure I understand. My DialogResult.OK is Closing the form. And that's good. I want it to close the form. I just don't want it to redirect after the form closes.
    – Riggy
    Aug 12, 2015 at 14:09
  • You are closing the Dialog with ok by yourself? However, I don´t think there is an to disable the page from redirecting. because usually it will Redirect and won´t stay in the newDocPage. But if you want to investigate it, I suggest you try with the page without modaldialog, thats where you could play around with eg URL Parameters more easily Aug 12, 2015 at 14:16
  • Oh I am sorry I think I didn't explain what I mean. The user will be in a doc library and push a button to bring up newDocSet dialog. After newDocSet dialog closes, It immediately redirects to INSIDE the docset. I want the dialog to close and have the user stay at the document library level. see what I mean?
    – Riggy
    Aug 12, 2015 at 14:25

Your Answer

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

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