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);
}

Saturday, March 14, 2015

OnBase Unity Script to Create a User

The following C# Unity script snippet could be used to create OnBase User accounts before the users actually log in. This is useful if you want to provision the User account, group memberships, and load balancing without burdening the User to log in first.

ctx = new PrincipalContext(ContextType.Domain, "<your company's domain>");
UserAdministration userAdmin = g_Application.Core.UserAdministration;

//loop through all users in a list <listADUsers>
//check if user is in the OnBase core group
User OBuserTemp = g_Application.Core.GetUser(AddOBUser);
UserGroupList obusergrps = OBuserTemp.GetUserGroups();
Boolean onbasegrptest = false;

foreach (string ADUser in listADUsers)
{
AddOBUser = ADUser.ToString().ToUpper();

UserPrincipal user = new UserPrincipal(ctx);
PrincipalSearcher srch = null;
srch = new PrincipalSearcher(user);
user.SamAccountName = AddOBUser;
srch = new PrincipalSearcher();
srch.QueryFilter = user;
PrincipalSearchResult<Principal> result = srch.FindAll();
Principal Psrch = result.ToList()[0];
DirectoryEntry Dresult = (DirectoryEntry)Psrch.GetUnderlyingObject();

String EmailAddress = Dresult.Properties["mail"].Value.ToString();
String DisplayName = Dresult.Properties["displayName"].Value.ToString();

//create user and add to selected group
NewUserProperties userProperties = userAdmin.CreateNewUserProperties(AddOBUser, "<default password>");
userProperties.EmailAddress = EmailAddress;
userProperties.RealName = DisplayName;
User OBuser = userAdmin.CreateUser(userProperties);
userAdmin.AddUserToGroups(OBuser, grpList);
user.Dispose();
srch.Dispose();
Psrch.Dispose();
result.Dispose();
Dresult.Dispose();
}

Saturday, March 7, 2015

OnBase Unity Script to Add Active Directory Group Members to OnBase Group

The following search Active Directory for a specific group and members and adds these members to the corresponding OnBase Group.

namespace AddADGroupMembersToOnBase
{
    using System;
    using System.Text;
    using Hyland.Unity;
    using Hyland.Unity.Workflow;
    using System.Data.Odbc;
    using System.Collections;
    using System.DirectoryServices;
    using System.DirectoryServices.AccountManagement;
    using System.Collections.Generic;

    /// <summary>
    /// This adds AD members from AD group to OnBase group.
    /// </summary>
    public class AddADGroupMembersToOnBase : Hyland.Unity.IWorkflowScript
    {
        private Hyland.Unity.Document _doc;
        private Hyland.Unity.Application _app;
        private Hyland.Unity.WorkflowEventArgs _args;
        private PrincipalContext ctx;

        #region IWorkflowScript
        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
_app = app;
_doc = args.Document;
_args = args;
     
           try{
               

ctx = new PrincipalContext(ContextType.Domain, "<your company domain>");
GroupPrincipal grp = null;
string gName = "<the AD group name to search>";
                grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, gName);
ArrayList ADUserList = new ArrayList();

                int numofusers = 0;

//find all AD users
                    foreach (Principal p in grp.GetMembers(true))
                    {
                        DirectoryEntry Dresult = (DirectoryEntry)p.GetUnderlyingObject();
                        String Attr1 = Dresult.Properties["userAccountControl"].Value.ToString();
                        if (Attr1 == "512")
                            ADUserList.Add(p.SamAccountName.ToUpper());
                        Dresult.Dispose();

                        numofusers++;
                    }

                    //list AP Approvers from OnBase group
                    UserGroup usrGroup;
                    UserList users;
                    ArrayList OBUserList = new ArrayList();
                    usrGroup = _app.Core.UserGroups.Find(gName);
                    users = _app.Core.UserAdministration.GetUsers(usrGroup);

                    foreach (User user in users)
                    {
                        OBUserList.Add(user.Name.ToString().ToUpper());
                    }

                    grp.Dispose();
                    ctx.Dispose();

                    foreach (string ADUser in ADUserList)
                    {
                       if (!OBUserList.Contains(ADUser))
                       {
                          addAPMember(ADUser, gName);
                       }
                    }
}
catch (Exception ex)
{
_app.Diagnostics.Write(ex);
_args.ScriptResult=false;
}
        }


private void addAPMember(string APMember, string gName)
        {
            try
            {
                if (_app.Core.GetUser(APMember) != null)
                {
                    UserAdministration userAdmin = _app.Core.UserAdministration;
                    List<UserGroup> grpList = new List<UserGroup>();
                    UserGroup grpToAdd;

                    //add the onbase core group
                    grpToAdd = _app.Core.UserGroups.Find(gName);
                    grpList.Add(grpToAdd);
                    
                    //add OB user to selected group
                    userAdmin.AddUserToGroups(_app.Core.GetUser(APMember.ToUpper()), grpList);
}

            }catch (Exception ex)
{
_app.Diagnostics.Write(ex);
_args.ScriptResult=false;
}
        }
        #endregion
    }
}

OnBase VB Script to send an email

The following is a sample OnBase VB Script to use to send an email.

Sub Main35()

Const CONNECTSTRING = "DSN=OnBase;UID=<ownerID>;PWD=<ownerPSWD>"

' Root level OnBase Automation object
  Dim oApp
  Set oApp = CreateObject("OnBase.Application")


   oApp.ExecutionStatus = 1

'set up parameters for CDO
strSMTPFrom = "support@yourcompany.com"
strSMTPTo = "level1support@yourcompany.com"
strSMTPRelay = "smtp.yourcompany.com"
strTextBody = "There are too many errors on the server"
strSubject = "ALERT: check OnBase processor server"
strAttachment = ""

'Create and set up CDO object
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
oMessage.Configuration.Fields.Update

'send message
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
'oMessage.AddAttachment strAttachment
oMessage.Send

Set oMessage = Nothing


End Sub 'Main35()

Sunday, March 1, 2015

OnBase Scan Queue Tools

If your company's ECM operation is scanning, indexing, and committing hundreds of scan batch a day, you may want to have extra insight into the daily processing metrics. You may also need to drill down into the scanning and logging to investigate issues.

The Scan Queue Tool allows you to search Scan Queues by the state of each scan by Scan Batches by Date Range. If the scan queue is configured to send out HL7 messages, you can use it to find a text string with the message. For HL7 translations, you can find information base on the mapping values.


Please see the tool's screen shot below.




If you are interested in using this tool for a free trial, or have suggestions on other functionality, please contact me at webber_john@charter.net.