cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for example Unity API code to use as IExternalKeywordDataSetScript.

Curtis_Krol1
Champ on-the-rise
Champ on-the-rise

Looking for example Unity API code to use as IExternalKeywordDataSetScript set, now that SQL Select String is no longer available.

 

I have 1 SQL table with Employee Information that used to be a very simple query. (Select ID, FName, LName From Employees Where ID = 'at- primary')

With that no longer an option, I am hoping people can share their code for this in Unity Scripts. When I look at the API, the sample does not complete the picture of how to query, build a results list, and then provide that back to the user within the Indexing screen, just: 

args.Results.AddKeyword( KeywordResult );

 

https://sdk.onbase.com/unitySDK/html/7f924cd4-f368-463d-8093-536d89ec9861.htm

I have scripts that make a connection string, and select/insert to other tables. How does the IExternalKeywordDataSetScript know it is an array of multiple keyword values? etc.

Thanks in advance.

16 REPLIES 16

Chuck_Dufour
Champ on-the-rise
Champ on-the-rise

Here is one I did a couple weeks ago in a Unity Script.  Hope it helps.

 

public void OnExternalKeywordDataSetScriptExecute(Hyland.Unity.Application app, Hyland.Unity.ExternalKeywordDataSetEventArgs args){  KeywordType kType = args.KeywordType;  SqlConnection connection = new SqlConnection();  SqlCommand command = new SqlCommand("SELECT Name FROM database.table WHERE group =   GroupName",connection);  connection = (SqlConnection)app.Configuration.GetConnection("myconnection");  connection.Open();  command.Connection = connection;  string sName;  try  {    SqlDataReader dr = command.ExecuteReader();    while (dr.Read())    {      sName = dr[0].ToString();      args.Results.AddKeyword(kType.CreateKeyword(sName));    }  }  catch (Exception ex)  {    app.Diagnostics.Write("Exception: "+ ex.ToString());  }  connection.Close();}

Jeffrey_Seaman
Star Contributor
Star Contributor

Based on the query example you provided, it looks like maybe you are looking for Working with External AutoFill Keyword Sets instead.

 

As for an example, here is one of my scripts. I have a stored procedure which returns columns which match the names of my keyword types. In my case, all are alphanumeric. This allows me to loop through each record, read each column name, and create a keyword of that type with the appropriate value. Once the row has been fully processed, it is added to the results.

 

	public void OnExternalAutofillKeysetScriptExecute(Hyland.Unity.Application app, Hyland.Unity.ExternalAutofillKeysetEventArgs args)	{		string searchValue = args.PrimaryKeyword.AlphaNumericValue;				string spName = "dbo.GetClientDataByCaseNumber";		try		{			using (var sqlConn = (SqlConnection)app.Configuration.GetConnection("ConnectionNameGoesHere"))			{				sqlConn.Open();				using (var sqlComm = new SqlCommand(spName, sqlConn))				{					sqlComm.CommandType = CommandType.StoredProcedure;					sqlComm.Parameters.AddWithValue("@caseNumber", searchValue);					var reader = sqlComm.ExecuteReader();					while (reader.Read())					{						var record = args.Results.CreateExternalAutofillKeysetData();						for (int i = 0; i < reader.FieldCount; i++)						{							var keyType = app.Core.KeywordTypes.Find(reader.GetName(i));							string value = reader.GetValue(i).ToString();							if (keyType != null)							{								if (value.Length > keyType.DataLength)								{									value = value.Substring(0, (int)keyType.DataLength);								}								var keyword = keyType.CreateKeyword(value);								record.SetKeyword(keyword);							}						}						// Add record to the autofill results						args.Results.AddExternalKeywordAutofillKeysetData(record);					}				}			}		}		catch (Exception ex)		{			app.Diagnostics.Write("Error retrieving client autofill by case number: " + ex);		}	}

Curtis_Krol1
Champ on-the-rise
Champ on-the-rise

Thanks to both of you!
Jeffery, this appears to be exactly what i needed to get started.
Chuck, that was going to be my next step, to build the full set of data.

It is just frustrating that Hyland takes away simple functionallity that has been in place for decades without providing guidance on their suggested alternative.

Rose_Nedrow
Confirmed Champ
Confirmed Champ

Hello.

 

I apologize for frustration this has caused.  Please know that the ability to configure SQL Select and VB Scripts is still available and is enabled by default for existing customers.  New customers have these settings disabled by default and we do recommend all customers use alternate sources, such as Unity Scripts.  Please see the System Administration MRG for more information.  This change was introduced in OnBase Foundation EP5 (LTR). 

I will keep your feedback in mind and will strive to provide guidance in the future. 

 

Thank you,

Rose Nedrow