using System; using SiebelBusObjectInterfaces; using System.Collections.Generic; using System.Runtime.InteropServices; namespace MisconfigFields { /// /// Sample code that uses the Siebel COM interface to detect misconfigured /// fields. If there are any errors, a message with "ERROR" prefix would be /// displayed /// class Program { /// Set this to the correct connection string. The format is /// host=\"siebel://:// public const string ConnectString = "host=\"siebel://MyServer:2321/sieb78/SSEObjMgr_enu"; /// Set this to the correct username public const string Username = "foo"; /// Set this to the correct password public const string Password = "bar"; /// Change this to the name of the active repository public const string RepositoryName = "Siebel Repository"; /// Change this to the name of business object of interest public const string BOName = "Account"; /// Change this to the name of business component of interest public const string BCName = "Account"; static void Main(string[] args) { SiebelDataControl sdc = null; bool loggedIn = false; try { // Connect to Siebel sdc = new SiebelDataControl(); sdc.EnableExceptions(1); sdc.Login(ConnectString, Username, Password); loggedIn = true; // Retrieve all the fields for the specified business component List fieldNames = GetFields(sdc); foreach (string fieldName in fieldNames) { Console.WriteLine(fieldName); } // Issue a query & retrieve the field values // If there are any problematic fields, error messages would be // displayed for those Query(sdc, fieldNames); } catch (Exception e) { Console.WriteLine("ERROR: " + e.ToString()); } finally { if (loggedIn) { sdc.Logoff(); } if (sdc != null) { Marshal.ReleaseComObject(sdc); } } Console.WriteLine("Press ENTER to terminate..."); Console.ReadLine(); } /// /// Retrieves the names of the fields for the specified business /// component. It does so by looking up the repository. /// private static List GetFields( SiebelDataControl sdc ) { SiebelBusObject sbo = null; SiebelBusComp sbc = null; List fieldNames = new List(); try { // Get the business object and component instances sbo = sdc.GetBusObject("Repository Business Component"); sbc = sbo.GetBusComp("Repository Field"); // Query the repository for fields sbc.ActivateField("Name"); sbc.ClearToQuery(); sbc.SetSearchSpec("Repository Name", RepositoryName); sbc.SetSearchSpec("Parent Name", BCName); sbc.SetSearchSpec("Inactive", "N"); sbc.ExecuteQuery(1); if (!sbc.FirstRecord()) { Console.WriteLine("ERROR: GetFields - There are no fields in business component {0}", BCName); return fieldNames; } // Retrieve the field names do { fieldNames.Add(sbc.GetFieldValue("Name")); try { if (!sbc.NextRecord()) { break; } } catch (Exception) { break; } } while (true); } catch (COMException e) { Console.WriteLine("ERROR: GetFields - " + e.Message); } finally { if (sbc != null) { sbc.DeactivateFields(); Marshal.ReleaseComObject(sbc); sbc = null; } if (sbo != null) { Marshal.ReleaseComObject(sbo); sbo = null; } } return fieldNames; } /// /// Executes a "match all" query on the business component. For the /// first record, it will try to retrieve the values of the fields /// one at a time. If there are any errors, the error message would be /// displayed along with the field name. /// private static void Query( SiebelDataControl sdc, List fieldNames ) { SiebelBusObject sbo = null; SiebelBusComp sbc = null; try { // Get the business object and component instances sbo = sdc.GetBusObject(BOName); sbc = sbo.GetBusComp(BCName); // Activate the fields foreach (string fieldName in fieldNames) { sbc.ActivateField(fieldName); } // Execute the query sbc.ClearToQuery(); sbc.SetSearchExpr("[Id] LIKE \"*\""); sbc.ExecuteQuery(1); if (!sbc.FirstRecord()) { Console.WriteLine("ERROR: Query - There are no records for business component {0}", BCName); return; } // Retrieve the field values, ignoring errors if any foreach (string fieldName in fieldNames) { try { sbc.GetFieldValue(fieldName); } catch (Exception e) { Console.WriteLine("ERROR: Query - Error retrieving value of field {0}. {1}", fieldName, e.Message); } } } catch (COMException e) { Console.WriteLine("ERROR: Query - " + e.Message); } finally { if (sbc != null) { sbc.DeactivateFields(); Marshal.ReleaseComObject(sbc); sbc = null; } if (sbo != null) { Marshal.ReleaseComObject(sbo); sbo = null; } } } } }