cancel
Showing results for 
Search instead for 
Did you mean: 

Anyone have an example of using a unity script with an external workview class, creating the external objects and adding them to the results set?

Michael_Schrote
Champ on-the-rise
Champ on-the-rise

Just what the subject says. I've scoured the SDK and can't find any examples of using a unity script to populate a query for an external class. Any sample code is HIGHLY appreciated.

Thanks!

6 REPLIES 6

Jayson_Roman
Champ on-the-rise
Champ on-the-rise
Hi Alex

I have a web service that I need to populate into a filter from an external Class. can you share the example you talk about in the previous comment please. jaysonr2003@yahoo.com will appreciated!

BarbaraEbel
Star Contributor
Star Contributor

Michael has moved on from the OnBase world, but here is a daily Claims script he wrote to pull from an external database and create workview objects from the returned rows:

 

// Skeleton generated by Hyland Unity Editor on 4/27/2017 2:32:20 PM
namespace ClaimsAuditQuery
{
using System;
using System.Text;
using Hyland.Unity;
using Hyland.Unity.Workflow;
using Hyland.Unity.WorkView;
using Oracle.DataAccess.Client;
using System.Data.OracleClient;
using System.Data.Common;


/// <summary>
/// Part one of three for grabbing and creating Local Claims for Auditing
/// </summary>
public class ClaimsAuditQuery : Hyland.Unity.IWorkflowScript
{

#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)
{
try
{
//string output = "";

//Connection String
var dbConnection = app.Configuration.GetConnection("EXTERNAL_DB");


app.Diagnostics.Write("Audit Query Script Version 9");

//Find the WV Application
Hyland.Unity.WorkView.Application application = app.WorkView.Applications.Find("Claims Audit");

//Find the WV Class
Hyland.Unity.WorkView.Class localClaims = application.Classes.Find("LocalClaims");



//declare string for whether connection is successful
string connSuccess;

//Check if connection successful

if (dbConnection == null)
{
connSuccess = string.Format("Connection {0} does not exist.", dbConnection);
app.Diagnostics.Write("Connection not successful");
}
else
{
connSuccess = string.Format("Connection {0} found.", dbConnection);
app.Diagnostics.Write("Success!");

using (var cmd = dbConnection.CreateCommand())
{
string queryString = @"SELECT clcl.clcl_id AS claim_id,
grgr.grgr_id AS group_id,
clst.usus_id AS user_id,
clcl.pdds_mctr_bcat AS bus_cat,
clst.clst_sts_dtm AS status_date,
COALESCE(clst2.clst_sts, clst.clst_sts) status,
clcl.clcl_tot_chg AS total_charge,
clst.clst_seq_no AS sequence_no,
COALESCE(clst2.clst_seq_no, clst.clst_seq_no) prev_seq_no,
CASE
WHEN clst2.clst_mctr_reas = ' '
THEN 'C000'
WHEN clst2.clst_mctr_reas is null
THEN 'C008'
ELSE clst2.clst_mctr_reas
END AS pend_reason,
clcl.clcl_cur_sts current_status,
clcl.clcl_tot_payable AS total_paid,
'Normal Audit' AS type_of_audit
FROM SOME_TABLES
";

app.Diagnostics.Write("queryString = " + queryString);

dbConnection.Open();

cmd.CommandText = queryString;

using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
app.Diagnostics.Write("Claim ID: " + reader[0].ToString());
/*app.Diagnostics.Write("User ID: " + reader[1].ToString());
app.Diagnostics.Write("Business Category: " + reader[2].ToString());
app.Diagnostics.Write("Processed Date: " + reader[3].ToString());
app.Diagnostics.Write("Status: " + reader[4].ToString());
app.Diagnostics.Write("Total Charge: " + reader[5].ToString());
app.Diagnostics.Write("Sequence Number: " + reader[6].ToString());
app.Diagnostics.Write("Previous Sequence Number: " + reader[7].ToString());
app.Diagnostics.Write("Pend Reason: " + reader[8].ToString());
app.Diagnostics.Write("Current Status: " + reader[9].ToString());
app.Diagnostics.Write("Total Paid: " + reader[11].ToString());*/

//Place all values into placeholders
string ClaimID = reader[0].ToString();
string groupID = reader[1].ToString();
string UserID = reader[2].ToString();
string BusinessCategory = reader[3].ToString();
DateTime processedDate = DateTime.Parse(reader[4].ToString());
string status = reader[5].ToString();
decimal TotalCharge = decimal.Parse(reader[6].ToString());
int sequenceNumber = int.Parse(reader[7].ToString());
int previousSequenceNumber = int.Parse(reader[8].ToString());
string pendReason = reader[9].ToString();
string currentStatus = reader[10].ToString();
string typeOfAudit = reader[12].ToString();
decimal TotalPaid = decimal.Parse(reader[11].ToString());

//app.Diagnostics.Write("Decimal total charge: " + TotalCharge);
//string BusinessCategory = reader[6].ToString();

//string UserID = reader[7].ToString();

//Create New Object
Hyland.Unity.WorkView.Object newObject = localClaims.CreateObject(true);

// Create an AttributeValueModifier for this object; which can be used
// to modify or save attribute values to this object
Hyland.Unity.WorkView.AttributeValueModifier attrValueModifier = newObject.CreateAttributeValueModifier();

//Get the Attribute Object back using the Attribute Name
Hyland.Unity.WorkView.Attribute ATTRIBUTEOBJECT = localClaims.Attributes.Find("ClaimID");

// Set the attribute value with the specified attribute name
//attrValueModifier.SetAttributeValue("ClaimID", reader[0].ToString());
attrValueModifier.SetAttributeValue("ClaimID", ClaimID);

// Set the attribute value with the specified attribute object
//attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, reader[0].ToString());
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, ClaimID);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("UserID");
attrValueModifier.SetAttributeValue("UserID", UserID);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, UserID);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("BusinessCategory");
attrValueModifier.SetAttributeValue("BusinessCategory", BusinessCategory);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, BusinessCategory);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("ProcessedDate");
attrValueModifier.SetAttributeValue("ProcessedDate", processedDate);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, processedDate);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("Status");
attrValueModifier.SetAttributeValue("Status", status);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, status);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("TotalCharge");
attrValueModifier.SetAttributeValue("TotalCharge", TotalCharge);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, TotalCharge);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("SequenceNumber");
attrValueModifier.SetAttributeValue("SequenceNumber", sequenceNumber);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, sequenceNumber);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("PreviousSequenceNumber");
attrValueModifier.SetAttributeValue("PreviousSequenceNumber", previousSequenceNumber);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, previousSequenceNumber);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("PendReason");
attrValueModifier.SetAttributeValue("PendReason", pendReason);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, pendReason);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("CurrentStatus");
attrValueModifier.SetAttributeValue("CurrentStatus", currentStatus);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, currentStatus);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("Group");
attrValueModifier.SetAttributeValue("Group", groupID);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, groupID);

ATTRIBUTEOBJECT = localClaims.Attributes.Find("TotalPaid");
attrValueModifier.SetAttributeValue("TotalPaid", TotalPaid);
attrValueModifier.SetAttributeValue(ATTRIBUTEOBJECT, TotalPaid);

attrValueModifier.ApplyChanges();

}
}
app.Diagnostics.Write("Audit Query - Done");
dbConnection.Dispose();
}
}

}
catch (UnityAPIException uae)
{
app.Diagnostics.Write(uae);
}
catch (Exception ex)
{
app.Diagnostics.Write(ex);
}
}
#endregion
}
}