cancel
Showing results for 
Search instead for 
Did you mean: 

Delete orphan folders with Unity API

Brendan_Altman2
Star Contributor
Star Contributor

Is there a way to delete orphan folders with the Unity API or is that only accomplished in the thick client with scheudling tasks 

1 ACCEPTED ANSWER

Aki_Daiguji
Star Contributor
Star Contributor

Hi Brendan,

In Workflow, before you perform the action to auto-folder a document to another folder, you can run an action to get the folder that the active document is in, and put that  folder information into a PropertyBag. Then after the document is moved to another folder, run another action to delete the folder that is specified in the PropertyBag. This will delete orphaned folders that has been orphaned by this Workflow action.

View answer in original post

6 REPLIES 6

Sean_Killian
Elite Collaborator
Elite Collaborator

Hi, Brendan,

We do something similar to this to find folders with keyword values that shouldn't exist and delete the keywords:

We come up with the SQL to identify what we're looking for, e.g. in this case, something like:

SELECT foldernum FROM hsi.folder f WHERE NOT EXISTS (
        SELECT 1 FROM hsi.folder p WHERE f.parentfoldernum = p.foldernum
);

Possibly adding in parameters like a date range, set of which folder types should be included, etc.

  • Put that SQL into a Configuration Item
  • Create a Connection String that connects back into your OnBase database
  • Write a Unity Script that uses that connection string, loads the SQL from the Configuration Item, and executes it.  For each row in the results, get the foldernum column out of the row and use app.Core.FolderManagement.GetFolderByID(foldernum) to retrieve the folder.
  • Delete it with app.Core.FolderManagement.DeleteFolder(folder);

To tie together Sean's answer and the exact question Brendan asked-

It is *not* possible to use the API to just call one method and tell it "delete the orphaned folders".

It is possible to do the same work yourself using the API combined with SQL queries (just as Sean described).

It *might* be possible to do the same thing using pure API (no SQL of your own database), but the code would be muuuuuuuch more complex, much slower (maybe slow enough as to be effectively impossible in a reasonable sized environment), and there might be information you would need that just isn't available through the API.

Greetings Alex, 

I know that  the API can delete folder by ID with a short script

===========================================================

public void DeleteFolder(Hyland.Unity.Application G_Application)
{
if (G_Application != null)
{
try
{
lstoutput.Items.Clear();
Core C = G_Application.Core;

FolderManagement folderManager = C.FolderManagement;

Folder folder = folderManager.GetFolderByID(1659); 

folderManager.DeleteFolder(folder);

lstoutput.Items.Add("Folder Successfully Deleted");
}// end try
catch (UnityAPIException UnityEX)
{
lstoutput.Items.Add(UnityEX.Message);
G_Application.Diagnostics.Write(UnityEX.Message);
}// end catch

catch (Exception Ex)
{
lstoutput.Items.Add(Ex.Message);
G_Application.Diagnostics.Write(Ex.Message);
}// end catch
}//end if
else
{
lstoutput.Items.Clear();
lstoutput.Items.Add("You are Not Connected to OnBase");
}
}

======================================================

 

The folder auto-name string is the keyword (email address) 

When an action in workflow is performed the document will be auto-foldered into a new filing cabinet 

My goal is to delete the orphan folder it was originally in without have to wait 24 hours for a scheduled process to do so .  So my other question would be how can I identify that particular orphan folder with SQL to delete it ? 

 

 

 

 

 

 

Aki_Daiguji
Star Contributor
Star Contributor

Hi Brendan,

In Workflow, before you perform the action to auto-folder a document to another folder, you can run an action to get the folder that the active document is in, and put that  folder information into a PropertyBag. Then after the document is moved to another folder, run another action to delete the folder that is specified in the PropertyBag. This will delete orphaned folders that has been orphaned by this Workflow action.