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!