Tuesday, August 25, 2020

OnBase Unity Script to pre-fill data on in a Unity Form

The below code shows the nuts and bolts of updating a checkbox with lookup data via SQL.

namespace GetData

{

    using System;

    using System.Text;

    using Hyland.Unity;

    using Hyland.Unity.CodeAnalysis;

    using Hyland.Unity.UnityForm;

using System.Data.Odbc;

using System.Collections.Generic;

using System.Data.Common;

    

    

    /// <summary>

    /// This is to get data

    /// </summary>

    public class GetData : Hyland.Unity.UnityForm.IUnityFormCustomActionEventScript

    {

private string ODBCConnectionString = string.Empty;

        

        #region IUnityFormCustomActionEventScript

        /// <summary>

        /// Implementation of <see cref="IUnityFormCustomActionEventScript.OnCustomActionExecuteAction" />.

        /// <seealso cref="IUnityFormCustomActionEventScript" />

        /// </summary>

        /// <param name="app"></param>

        /// <param name="args"></param>

        public void OnCustomActionExecuteAction(Hyland.Unity.Application app, Hyland.Unity.UnityForm.UnityFormCustomActionEventArgs args)

        {

try{

app.Diagnostics.Level = Diagnostics.DiagnosticsLevel.Verbose;

//create form object

Hyland.Unity.UnityForm.Form form = args.FormInstance;


   // Get OnBase ODBC Connection string

app.Configuration.TryGetValue("ODBCConnectionString", out ODBCConnectionString);

   

bool bInsuranceCard = false;


using (OdbcConnection conn = new OdbcConnection(ODBCConnectionString))

    {

    conn.Open();

OdbcDataReader dr = null;

OdbcCommand cmd = null;

cmd = new OdbcCommand("select c.itemtypename from hsi.itemdata a "+

"join hsi.keyitem115 b on b.itemnum = a.itemnum "+

"and a.status = 0 "+

"and c.itemtypename in ('Insurance Card')", conn);

dr = cmd.ExecuteReader();

                while (dr.Read())

                {

if(dr[0].ToString().Trim().Equals("Insurance Card") || dr[0].ToString().Trim().Equals("Insurance Card-New PT Only"))

{

bInsuranceCard = true;

}

}

dr.Close();

cmd.Dispose();

                dr.Dispose();

}

if(bInsuranceCard) {

formmod.SetFieldValue("checkbox187InsuranceCard","1");

}else{

formmod.SetFieldValue("checkbox187InsuranceCard","");

}


   //Apply Changes to Form

formmod.ApplyChanges();

}

} catch (Exception ex)

         {

             app.Diagnostics.WriteIf(Diagnostics.DiagnosticsLevel.Error, "Error in Get Data: " +ex);

  

         }

        }

        #endregion

    }

}

Sunday, December 29, 2019

Using WorkView as Cascading Dataset

Have you ever wondered why cascading datasets in Unity Forms are still done at the keyword type letter in OnBase Config, or in Unity form datasets? There is a way to cascade datasets that is explained in the sdk using a external database, but what I will show you is a way to give Users access to data via WorkView and develop a Unity script to access it.

Components:

WorkView 

An application, class, and two attributes with data: the first keyword drop down value and the corresponding child (cascaded) values.

DocType

A doc type with two keywords, the initial keyword type and the child keyword type.

Keyword Type

The child keyword type will be set to run an "External" Unity script. The script will be set to "Send existing Keyord values form Unity Forms." Will be execute every time the parent value changes. The Unity script will return the "results" to the keyword select box on the form (based on the parent value selected).

Unity Script

The class of the script will extend "Hyland.Unity.IExternalKeywordDataSetScript".
You want to use WorkView:     "using workview = Hyland.Unity.WorkView;"

Snippet
// Get keyword types
string keywordValueParent= "";

KeywordType keywordValueParentKeyType  = application.Core.KeywordTypes.Find( "keywordTypeParent" );

KeywordRecord keywordValueParentRecord = arguments.SearchParameters.RelatedKeywordRecords.Find( keywordValueParentKeyType );

Keyword keywordValueParentKey = (keywordValueParentRecord != null) ? keywordValueParentRecord.Keywords.Find( keywordValueParentKeyType ) : null;
keywordValueParent = keywordValueParentKey.Value.ToString().Trim();

//run filter to get attribute values
string WVFilterName = "WV Filter all parent and child values";
 
//get workview objects for Training Review Log
workview.Application workViewApp = application.WorkView.Applications.Find("WV Application Name");
 
//get the wv filter
workview.Filter filter = workViewApp.Filters.Find(WVFilterName);

//Create a FilterQuery object
workview.FilterQuery filterQuery = filter.CreateFilterQuery();
 
filterQuery.AddConstraint("ParentValue", workview.Operator.Equal, keywordValueParent);
 
//Exec the filterQuery
workview.FilterQueryResultItemList results = filterQuery.Execute(100);

//Iterate thru results
foreach (workview.FilterQueryResultItem result in results)
{
    //get the column values
    workview.FilterColumnValue ReasonCode = result.GetFilterColumnValue("ChildValue");
    arguments.Results.AddKeyword( arguments.KeywordType.CreateKeyword(     
    ChildValue.Value.ToString() ) );
}

Wednesday, April 20, 2016

Unity Script: Scan Queue Filter for workflow routing

In certain situations when designing your workflow, you might find it necessary to filter out documents based on scan queue. As of V15, there is no way to configure this type of filter. You can filter by doc type and limiting your scan queue doc types, but what if you wanted to quality check all documents being scanned in except scans of any doc type coming from certain scan queues? In this case, the following Unity script could be helpful.

namespace ScanQueueFilter
{
    using System;
    using System.Text;
    using Hyland.Unity;
    using Hyland.Unity.Workflow;
    using System.IO;
    using System.Collections.Generic;
    using System.Collections;
    using System.Data.Odbc;
   
    /// <summary>
    /// scan queue filter to route incoming documents to their appropriate sub process
    ///
    /// </summary>
    public class ScanQueueFilter: Hyland.Unity.IWorkflowScript
    {
        private Hyland.Unity.Document _doc;
        private string ODBCOnBaseConnectionString = string.Empty;

        #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)
        {
                _doc = args.Document;
                string keyvalue = null;

                bool IsInScanQueueScope = false;
                                                               
                //check for doc inclusion in scan queue scope
                string dochandle = _doc.ID.ToString();
                                                               
                //get ODBC connection
                app.Configuration.TryGetValue("ODBCOnBaseConnectionString", out ODBCOnBaseConnectionString);
                                               
                using (OdbcConnection conn = openODBCConnection()){
                OdbcDataReader dr = null;
                OdbcCommand cmd = null;
                                                               
                cmd = new OdbcCommand("select a.itemnum, a.itemname " +
                "from itemdata a, archivedqueue b " +
                "where a.batchnum = b.batchnum " +
                "and a.itemnum = '"+dochandle+"' " +
                "and b.queuenum in ('221')", conn);
                //221 is the scan queue configuration number
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                 IsInScanQueueScope = true;
                 break;
                }
                                                                                                                            dr.Close();
                                                                                                
                }
                                                               
                 if(IsInScanQueueScope){
                    args.ScriptResult=true;
                 }else{
                    args.ScriptResult=false;
                 }

           }

Tuesday, September 1, 2015

OnBase Unity C# Visual Studio: Create an ODBC connection

Core to creating an OnBase Visual Studio application is to connecting to and querying the onbase database instance for various activities outside of what the API exposes. Here are the steps to do this:


  1. Install the ODBC driver for your OnBase database
  2. Configure a Data Source Name entry
  3. Import the ODBC class for reference
  4. Write code to establish a connection object
  5. Open a connection
  6. Run through the results
  7. Close a connection
Here's some of the code to help do this:

... main code


                OdbcConnection conn = openODBCConnection();
                OdbcDataReader dr = null;
                OdbcCommand cmd = null;

                cmd = new OdbcCommand("select a.keyvaluechar from keyitem141 a  " +
                "where a.itemnum = '" + itemnumtemp + "'", conn);

                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    TempValue = dr[0].ToString().Trim();
                }

                conn.Close();
                cmd.Dispose();
                dr.Dispose();

... connection method
                 conn.ConnectionString = "DSN=OnBaseDSN;UID=hsi;PWD=password"

OnBase Unity C# Visual Studio: update a keyword value

Ok, from previous posts, we know how to do the following: create an app connection, get a doc ID, create a doc object. Once we have those, we can modify a keyword's value. Note: this is not the same as adding a keyword, which is what you want to do if one doesn't exist. Hope this helps...

                        // check whether document was locked
                        if (documentLock.Status == DocumentLockStatus.LockObtained)
                        {

                            KeywordModifier keyModifier = doc.CreateKeywordModifier();

                            KeywordType searchKeywordType = g_Application.Core.KeywordTypes.Find("Your Date");

                            // loop thru keyword records
                            foreach (KeywordRecord keyRecord in doc.KeywordRecords.FindAll(searchKeywordType))
                            {
                                // loop though keywords
                                foreach (Keyword keywordOld in keyRecord.Keywords.FindAll(searchKeywordType))
                                {

                                    // Find Keyword Type 
                                    KeywordType keywordType0 = core.KeywordTypes.Find("Your Date");

                                    // Create Keyword Object
                                    DateTime newdate1 = DateTime.ParseExact(strDate,"MM/dd/yyyy", null);
                                    string strDatex = newdate1.ToString("MM-dd-yyyy");
                                    DateTime NewDateValue = Convert.ToDateTime(strDatex);

                                    Keyword keywordNew = keywordType0.CreateKeyword(NewDateValue);
                        
                                    //update keyword
                                    keyModifier.UpdateKeyword(keywordOldkeywordNew);

                                  
                                }
                            }

                            //Apply changes
                            keyModifier.ApplyChanges();

                            //release doc lock
                            documentLock.Release();
                           }

OnBase Unity C# Visual Studio: attach a lifecycle

As I've shown in a previous post, you'll need to create an application connection, find the doc handle of the doc you want to attache a lifecycle to, and create the doc object. Once you'll done that, you'll need to create the workflow and lifecycle objects. Then, add the doc to the lifeycle;


                    Workflow workflow = g_Application.Workflow;
                    LifeCycle lifeCycle = g_Application.Workflow.LifeCycles.Find(<config number of the                       lifecycle);
                    workflow.AddDocumentToLifeCycle(doc, lifeCycle);

OnBase Unity C# Visual Studio code to create a document object

In many cases you'll need a document object to perform actions on it. Here are the basics:

Create an application session
        AuthenticationProperties authProps = null;
              authProps = Hyland.Unity.Application.CreateDomainAuthenticationProperties(TestAppServer, TestDatabase);
                authProps.LicenseType = LicenseType.Default;
                  g_Application = Hyland.Unity.Application.Connect(authProps);

          Run your query to find the document's handle. Creating a SQL connection and running it is in a separate post.

                  long docID = Convert.ToInt64(dr[0].ToString().Trim());

                  Document doc = g_Application.Core.GetDocumentByID(docID);

          Once you have a document object you can update keys, attach lifecycles, etc.