Tuesday, February 24, 2015

OnBase Unity Workflow script to create a note

Below is a method that creates an OnBase note which is attached to the doc being processed.
It accepts a string which will the text that is meant to show in the note.

private void createNote(string noteText)
{
    //Create a Note with the error message
    NoteType noteType = _app.Core.NoteTypes.Find("<note type>");
    NoteModifier noteMod = _args.Document.CreateNoteModifier();

    //Properties of the Note
    NoteProperties noteProps = noteMod.CreateNoteProperties();
    noteProps.Text = "Validation Issue" + Environment.NewLine + "Error               Message: "+ noteText;
    
    //Create the New Note
    Note newNote = noteType.CreateNote(noteProps);
    noteMod.AddNote(newNote);
    noteMod.ApplyChanges();

    //_app.Diagnostics.Write("Note Added");
}

OnBase Unity Workflow script to export a doc to the directory


Below is an OnBase unity workflow script to export a doc to the directory. Be sure to add the References that you are using.


namespace _SaveToFile
{
    using System.IO;
    using System.Text;
using System;
    using Hyland.Unity;
    using Hyland.Unity.Workflow;
    
    
    /// <summary>
    /// script for doing something in a workflow
    /// </summary>
    public class _SaveToFile : Hyland.Unity.IWorkflowScript
    {
        
        #region IWorkflowScript
        //<summary>
       //  Implementation of the export to file share of the 3M integration
       // </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>

        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)

        {
try
            {
Document wfdoc = args.Document;
            //Application _app = app;
string url = "<application service URL";
string username = "<manager account";
string password = "<manager password";
string datasource = "DSN of OnBase database";

//Create a new Unity Integration Application Object
OnBaseAuthenticationProperties props = Application.CreateOnBaseAuthenticationProperties(url, username, password, datasource);
props.LicenseType = LicenseType.Default;
Application _app = Application.Connect(props);


string dirPath = @"\\FileServer\Share\" + args.Document.ID + ".";

                // create Redition

                Rendition wfrend = wfdoc.DefaultRenditionOfLatestRevision;

                //PageData

                using (PageData wfPageData = _app.Core.Retrieval.Image.GetDocument(wfrend))
                {
                    //Utility to write data page stream
                    Utility.WriteStreamToFile(wfPageData.Stream, dirPath + wfPageData.Extension);
                }

args.ScriptResult = true;

_app.Disconnect();

            }
            catch (UnityAPIException Uex)
            {
                app.Diagnostics.Write("Unity API: "+Uex.Message);
args.ScriptResult = false;
            }
            catch (Exception ex)
            {
                app.Diagnostics.Write("Exception: "+ex.Message);
            args.ScriptResult = false;
}

        }

        #endregion
    }
}

OnBase Unity Workflow Script ODBC connection method

Here is a standard OnBase workflow ODBC connection method.

  • You have to have the DSN setup on the machine that is running the workflow process/timer.
  • You need to add a Reference in the Unity IDE
namespace <project name>
{


    using Hyland.Unity;
    using Hyland.Unity.Workflow;
    using System.Data.Odbc;
...

    public class <project name> : Hyland.Unity.IWorkflowScript
    {
...
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
         
OdbcConnection conn = openODBCConnection();
...
         }
...
private OdbcConnection openODBCConnection()
        {
            var conn = new OdbcConnection();
            conn.ConnectionString = "DSN=OnBaseDSN;UID=<instance user>;PWD=<password>";
            conn.Open();
            return (conn);
        }