Thursday, March 26, 2015

OnBase Unity Script to Import Content

This script is not complete, but should show the essential components that assure the ability to import content into OnBase. Typically when you are importing via a script, you are reading an index file line by line and using these values along with a pointer to a file in a folder to import. Enjoy!

To import you'll need a value for the file type, the OnBase document type, some descriptive keyword types, and a file list.

get an application session:
getOnBaseAppSession(); //see method below

Setup the file type for import:

if (filetype == "TIF")
{
filetype = "Image File Format";
}

Loop through the index file, reading each line and splitting the values:

StreamReader file = new StreamReader(path);
while ((line = file.ReadLine()) != null)
{
...

string[] indexValues = line.Split(delimiterChar);
...

importDoc(doctypetemp, filetypetemp, fileList, Sourcekeywords);

}

The importDoc method will do all of the OnBase importing:

private void importDoc(string doctypetemp, string filetypetemp, List<string> fileList, string Sourcekeywords)
{
try...
//set the storage
Storage storage = g_Application.Core.Storage;

//set the doc type
DocumentType documentType = g_Application.Core.DocumentTypes.Find(doctypetemp);

//Set file type 
FileType fileType = g_Application.Core.FileTypes.Find(filetypetemp);

// create storage props from the storage object
StoreNewDocumentProperties storeDocumentProperties = storage.CreateStoreNewDocumentProperties(documentType, fileType);

// Add keyword record to storage properties
storeDocumentProperties.AddKeyword("Account#", Accounttemp);

// storeDocumentProperties.ExpandKeysets = true;

// Assign document date 
storeDocumentProperties.DocumentDate = DateTime.Now;

// Allow document to be auto named 
//storeDocumentProperties.AutoName = true;

// Add comment 
storeDocumentProperties.Comment = "Custom Import";

// Do not add document to workflow 
storeDocumentProperties.Options = StoreDocumentOptions.SkipWorkflow;

//import!
Document newDocument = g_Application.Core.Storage.StoreNewDocument(fileList, storeDocumentProperties);

}

private void getOnBaseAppSession()
{
try
{
//connect to OnBase 
AuthenticationProperties authProps;
authProps = Hyland.Unity.Application.CreateDomainAuthenticationProperties(<TestAppServer>, <TestDatabase>);
authProps.LicenseType = LicenseType.Default;
g_Application = Hyland.Unity.Application.Connect(authProps);
}

No comments:

Post a Comment