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

    }

}

1 comment: