0

SharePoint 2013 Enterprise, Visual Studio 2013 Premium

I have a requirement to re-open a record that has been moved to a records center. In our case, records consist of a custom DocumentSet based content type and documents within the DocumentSet. When they re-open it, I am to reset the Completion Date to null.

I think the best way to accomplish this is via the DocumentSet.SendToOfficialFile method. The following code snippet is from a Console Application I am using for proof of concept.

        try
        {

            using (SPSite site = new SPSite(recordUrl))
            {

                using (SPWeb web = site.RootWeb)
                {

                    // Parse out some url parameters we will need
                    Hashtable hash = ParseParametersFromUrl(recordUrl);
                    if (!hash.ContainsKey("List"))
                        throw new ArgumentException(string.Format("Could not parse the ListId from Url '{0}'", recordUrl));

                    // Get the documentset
                    Guid ListId = new Guid(hash["List"].ToString());
                    SPList list = web.Lists[ListId];
                    SPListItem item = list.GetItemById(Convert.ToInt16(hash["ID"]));
                    DocumentSet docset = DocumentSet.GetDocumentSet(item.Folder);

                    // Is it a record
                    Console.WriteLine(string.Format("   Is DocSet Record: {0}", Records.IsRecord(docset.Item)));

                    // Unrecord the files
                    foreach (SPFile f in docset.Folder.Files)
                    {

                        if (Records.IsRecord(f.Item))
                            Records.UndeclareItemAsRecord(f.Item); 

                    } // end foreach file

                    // Null the completion date
                    docset.Item["PICompletionDate"] = null;
                    docset.Item.Update();

                    // Build SPOfficialFileHost
                    string additionalInfo;
                    Uri tgtUri = new Uri(string.Format("http://mywebapp/activesite/_vti_bin/OfficialFile.asmx", docset.ContentType.Name));
                    SPOfficialFileHost targetHost = new SPOfficialFileHost();
                    targetHost.Action = SPOfficialFileAction.Move;
                    targetHost.Explanation = "Move to active";
                    targetHost.OfficialFileName = docset.Item.Title;
                    targetHost.OfficialFileUrl = tgtUri;
                    targetHost.ShowOnSendToMenu = false;

                    // SendTo active edit site
                    OfficialFileResult result = docset.SendToOfficialFile(docset.ContentType.Name, out additionalInfo, targetHost, null, SPOfficialFileSubmissionMode.None);

                    Console.WriteLine("additionalInfo: {0}", additionalInfo);
                    Console.WriteLine("result: {0}", result.ToString());

                } // end using SPWeb

            } // end using SPSite

            return true;
        }
        catch(Exception ex)
        {

            string msg = string.Format("Exception in ReOpen: {0}", ex.Message);
            Console.WriteLine();
            Console.WriteLine(msg);
            return false;

        } // end catch

    } // end Method ReOpen

Via the VS Debugger and various Console.WriteLine() statements, I can tell you all goes well until the docset.SendToOfficialFile line. Even that line executes without an exception, however, additionalInfo is empty and result is "Not Found".

Things I have verified:
1) The Content Organizer Settings at the SendTo destination
2) The OfficialFile.asmx Url at the SendTo destination
3) DocumentSet and Files are undeclared as records
4) The Completion Date property is updated to null

Things I have tried: 1) Non-null email address in the docset.SendToOfficialFile method call
2) Various incarnations of properties on SPOfficialFileHost properties
3) Even reversing the direction and sending to the records center

Can anyone spot a likely problem? Is there some content organizer configuration I may have missed that is required? Any explanation for the result Not Found?

0

Well, of course I figured this out not long after posting the question. I saw something in the ULS logs about not finding or not Assessing the OfficialFile.asmx so I looked at permissions groups. I noticed a group named "Records Center Web Service Submitters" and I added my user to that group. Re-executed the code posted above and it returned success and completed the move. That's a couple days of my work life I can't get back!

|improve this answer|||||

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.