cancel
Showing results for 
Search instead for 
Did you mean: 

Cascading data set using the Unity API IExternalKeywordDataSetScript

Thomas_Besnard
Champ in-the-making
Champ in-the-making

Hello,


I'm trying to make a script that populates cascading dataset using the Unity API IExternalKeywordDataSetScript.

One dropdown must contain the existing workflow names in the system and the other will contain the queues of the previously selected workflow.


I can't get the args.SearchParameters.RelatedKeywordRecords to be populated with the related keywords despite all of them are configured to "Send existing Keyword values from Unity Form".


For more information: the KW are currently configured as part of a MIKG. I also tried to create a Cascading Data Set with these kw and assign both MIKG and the Cascading Data Set to the document type as well as assigned only one or the other, nothing seemed to work.


Some help will be much appreciated.


Below is the script source.

The script output is:

"Looping through 0 kw records"

"No keyword record found for the keyword type zzzOB Maint WF Name"


// Skeleton generated by Hyland Unity Editor on 9/21/2018 1:57:15 PMnamespace THBECascadingTest{    using System;    using System.Text;	using System.Collections.Generic;    using System.Data.SqlClient;    using Hyland.Unity;	using Hyland.Unity.UnityForm;    using Hyland.Unity.CodeAnalysis;        public class THBECascadingTest : Hyland.Unity.IExternalKeywordDataSetScript    {                #region IExternalKeywordDataSetScript        public void OnExternalKeywordDataSetScriptExecute(Hyland.Unity.Application app, Hyland.Unity.ExternalKeywordDataSetEventArgs args)        {            app.Diagnostics.Level = Diagnostics.DiagnosticsLevel.Verbose;            try            {                app.Diagnostics.WriteIf( Diagnostics.DiagnosticsLevel.Verbose, string.Format( "Starting cascade test v34" ) );				string dbstring = app.Configuration.GetConnection("SB_ONBASE").ConnectionString;												KeywordType WFKeytype  = app.Core.KeywordTypes.Find( "zzzOB Maint WF Name" );				if (WFKeytype == null) {					throw new Exception("Keyword type doesn't exist: "+WFKeytype.Name);				} 				KeywordType QueueKeytype  = app.Core.KeywordTypes.Find("zzzOB Maint WF Issue WF Queue");				if (QueueKeytype == null) {					throw new Exception("Keyword type doesn't exist: "+QueueKeytype.Name);				}												if (args.SearchParameters.RelatedKeywordRecords == null) {					throw new Exception("No keyword record found in the script parameters");				} else {					app.Diagnostics.WriteIf( Diagnostics.DiagnosticsLevel.Verbose, "Looping through "+args.SearchParameters.RelatedKeywordRecords.Count+" kw records...");					int cpt = 0;					foreach (KeywordRecord rec in args.SearchParameters.RelatedKeywordRecords) {						app.Diagnostics.WriteIf( Diagnostics.DiagnosticsLevel.Verbose, cpt+" : "+rec.KeywordRecordType.Name );						cpt++;					}				}								KeywordRecord WFQueueKeyRecord = args.SearchParameters.RelatedKeywordRecords.Find( WFKeytype );				if (WFQueueKeyRecord == null) {					throw new Exception("No keyword record found for the keyword type "+WFKeytype.Name);				}								using (SqlConnection conn = new SqlConnection(dbstring)) {					conn.Open();										using (var cmd = conn.CreateCommand()){												if (args.KeywordType == WFKeytype) {							cmd.CommandText = @"select l.lifecyclename												from hsi.lifecycle l";													} else if (args.KeywordType == QueueKeytype) {							cmd.CommandText = @"select q.statename, l.lifecyclename												from hsi.lcstate q 												join hsi.lcxstate j on q.statenum = j.statenum												join hsi.lifecycle l on l.lcnum = j.lcnum												and l.lifecyclename=@workflowname";														Keyword WFKey = WFQueueKeyRecord.Keywords.Find(WFKeytype);							string WFName = WFKey.AlphaNumericValue;							cmd.Parameters.AddWithValue("@workflowname",WFName);						}												List<string> results = new List<string>();						using ( var reader = cmd.ExecuteReader() ) {	                        // Gather the results	                        while ( reader.Read() )	                        {	                            results.Add( reader.GetString(0) );	                        }	                    }						app.Diagnostics.WriteIf( Diagnostics.DiagnosticsLevel.Verbose, string.Format( "Found {0} records.", results.Count ));												foreach (string r in results) {							if ( r.ToUpper().Contains( args.SearchParameters.FilterText.ToUpper( ) ) )		                    {		                        args.Results.AddKeyword( args.KeywordType.CreateKeyword( r ) );		                    }						}					}				}											} catch (Exception ex) {				app.Diagnostics.Write(ex);			}        }        #endregion IExternalKeywordDataSetScript    }}
0 REPLIES 0